Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:45:20+00:00 2026-06-11T17:45:20+00:00

I am trying to use rsync with python. I have read that the preferred

  • 0

I am trying to use rsync with python. I have read that the preferred way to passing arguments to Popen is using an array.

The code I tried:

p = Popen(["rsync",
        "\"{source}\"".format(source=latestPath),
        "\"{user}@{host}:{dir}\"".format(user=user, host=host, dir=dir)],
        stdout=PIPE, stderr=PIPE)

The result is rsync asking for password, even though I have set up SSH keys to do the authentication.

I think this is a problem with the environment the new process gets executed in. What I tried next is:

p = Popen(["rsync", 
   "\"{source}\"".format(source=latestPath),
   "\"{user}@{host}:{dir}\"".format(user=user, host=host, dir=dir)],
   stdout=PIPE, stderr=PIPE, shell=True)

This results in rsync printing the “correct usage”, so the arguments are passed incorrectly to rsync. I am not sure if this is even supposed to work(passing an array with shell=True)

If I remove the array altogether like this:

p = Popen("rsync \"{source}\" \"{user}@{host}:{dir}\"".format(
        source=latestPath, user=user, host=host, dir=dir),
      stdout=PIPE, stderr=PIPE, shell=True)

The program works fine. It really doesn’t matter for the sake of this script, but I’d like to know what’s the difference? Why don’t the other two(mainly the first one) work?

Is it just that the shell environment is required, and the second one is incorrect?

EDIT: Contents of the variables

latestPath='/home/tomcat/.jenkins/jobs/MC 4thworld/workspace/target/FourthWorld-0.1-SNAPSHOT.jar'
user='mc'
host='192.168.0.32'
dir='/mc/test/plugins/'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:45:21+00:00Added an answer on June 11, 2026 at 5:45 pm

    I’d like to know what’s the difference?

    When shell=True, the entire command is passed to the shell. The quotes are there so the shell can correctly pick the command apart again. In particular, passing

    foo "bar baz"

    to the shell causes it to parse the command as (Python syntax) ['foo', 'bar baz'] so that it can execute the foo command with the argument bar baz.

    By contrast, when shell=False, Python will pass the arguments in the list to the program immediately. For example, try the following subprocess commands:

    >>> import subprocess
    >>> subprocess.call(["echo", '"Hello!"'])
    "Hello!"
    0
    >>> subprocess.call('echo "Hello!"', shell=True)
    Hello!
    0
    

    and note that in the first, the quotes are echoed back at you by the echo program, while in the second case, the shell has stripped them off prior to executing echo.

    In your specific case, rsync gets the quotes but doesn’t know how it’s supposed to handle them; it’s not itself a shell, after all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to launch an 'rsync' using subprocess module and Popen inside of a
I'm trying to use the result of ls in other commands (e.g. echo, rsync):
I am trying use gem tire to search in my application. I have tables
Hi I'm trying use a datepicker on a field I have. I'm trying to
I am trying to use rsync to take backup of a rapidly changing directory
I have been trying use the edit_post_link() function to contain an image. All of
I am trying use a javascript function while passing php variables in it. For
I am trying use a javascript function while passing php variables in it. For
I am trying use MySql and Entity Framework, using Connector/Net 6.1 with this as
Anyone know how to create a cvCreateStructuringElementEx using a image? I'm trying use opencv.cv.cvCreateStructuringElementEx()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.