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

  • SEARCH
  • Home
  • 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 6193789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:10:52+00:00 2026-05-24T03:10:52+00:00

I am using subprocess.check_call in combination with rsync. I need to use arguments for

  • 0

I am using subprocess.check_call in combination with rsync.

I need to use arguments for rsync that are coming from a string which contains multiple space separated values, however because the string is a single object it fails in the subprocess.check_call (which expects each argument to be a separate string).

This is what I’m talking about:

import subprocess
rsync_options = '-axh --delete --delete-excluded'
subprocess.check_call(['rsync', rsync_options, '/tmp/1', '/tmp/2'])

This returns the following expection:

subprocess.CalledProcessError: Command '['rsync', '-axh --delete --delete-excluded', '/tmp/1', '/tmp/2']' returned non-zero exit status 1

This works:

subprocess.check_call(['rsync', '-axh', '--delete', '--delete-excluded', '/tmp/1', '/tmp/2'])

How can I generate seperate strings from rsync_options and format them for use in subprocess.check_call also without knowing how many arguments might be provided?

  • 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-05-24T03:10:52+00:00Added an answer on May 24, 2026 at 3:10 am

    If I understand your question correctly, you can use shlex.split. (As JAB points out, rsync_options.split() is also an option in this particular case, but it fails in certain corner cases, as illustrated by the note here.)

    >>> import shlex
    >>> shlex.split('-axh --delete --delete-excluded')
    ['-axh', '--delete', '--delete-excluded']
    

    Then you can insert, append, or extend the result in any way you like.


    Perhaps the simplest way to construct the final list is concatenation:

    >>> rsync_options = '-axh --delete --delete-excluded'
    >>> rsync_args = ['rsync'] + shlex.split(rsync_options) + ['/tmp/1', '/tmp/2']
    >>> rsync_args
    ['rsync', '-axh', '--delete', '--delete-excluded', '/tmp/1', '/tmp/2']
    

    But that makes a copy. That probably won’t matter in this case, but just for the sake of completeness, here’s a way to do it without making a copy:

    >>> rsync_args = shlex.split(rsync_options)
    >>> rsync_args.extend(['/tmp/1', '/tmp/2'])
    >>> rsync_args.insert(0, 'rsync')
    >>> rsync_args
    ['rsync', '-axh', '--delete', '--delete-excluded', '/tmp/1', '/tmp/2']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to download files from the internet. For that I am using subprocess
I'm creating a python script that runs rsync using subprocess and then gets the
In one of my functions I'm calling an external program, using subprocess.check_call , which
I am using subprocess module for running commands from another app I know that
I create a subprocess using subprocess.Popen() that runs for a long time. It is
I'm having problems redirecting stdio of another program using subprocess module. Just reading from
I am using the subprocess package in Python to run a subprocess, which I
I have a ruby application that executes ant as a subprocess using backtick. This
I am writing a python program that lauches a subprocess (using Popen). I am
I need to interface a C console program (as subprocess) with Python using stdin/stdout.

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.