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 8433467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:23:38+00:00 2026-06-10T06:23:38+00:00

I have Python subprocess calls which are formatted as a sequence of arguments (like

  • 0

I have Python subprocess calls which are formatted as a sequence of arguments (like subprocess.Popen(['ls','-l']) instead of a single string (i.e. subprocess.Popen('ls -l')).

When using sequenced arguments like I did, is there a way to get the resulting string that is sent to the shell (for debugging purposes)?

One simple approach would be to join all arguments together myself. But I doubt this would in all cases be identical to what subprocess does, since the main reason for using a sequence is to ‘allow[s] the module to take care of any required escaping and quoting of arguments’.

  • 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-10T06:23:39+00:00Added an answer on June 10, 2026 at 6:23 am

    As mentioned in a comment, subprocess comes with (not documented in the docs pages) list2cmdline that transforms a list of arguments into a single string.
    According to the source doc, list2cmdline is used mostly on Windows:

    On Windows: the Popen class uses CreateProcess() to execute the child
    program, which operates on strings. If args is a sequence, it will be
    converted to a string using the list2cmdline method. Please note that
    not all MS Windows applications interpret the command line the same
    way: The list2cmdline is designed for applications using the same
    rules as the MS C runtime.

    Nevertheless, it’s quite usable on other OSes.

    EDIT

    Should you need the reverse operation (ie, splitting a command line into a list of properly tokenized arguments), you’ll want to use the shlex.split function, as illustrated in the doc of subprocess.

    >>> help(subprocess.list2cmdline)
    Help on function list2cmdline in module subprocess:
    
    list2cmdline(seq)
        Translate a sequence of arguments into a command line
        string, using the same rules as the MS C runtime:
    
        1) Arguments are delimited by white space, which is either a
           space or a tab.
    
        2) A string surrounded by double quotation marks is
           interpreted as a single argument, regardless of white space
           contained within.  A quoted string can be embedded in an
           argument.
    
        3) A double quotation mark preceded by a backslash is
           interpreted as a literal double quotation mark.
    
        4) Backslashes are interpreted literally, unless they
           immediately precede a double quotation mark.
    
        5) If backslashes immediately precede a double quotation mark,
           every pair of backslashes is interpreted as a literal
           backslash.  If the number of backslashes is odd, the last
           backslash escapes the next double quotation mark as
           described in rule 3.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python subprocess call which I would like to link up to
I have a python script which uses subprocess.Popen to run multiple instances of another
i have a python script which keeps crashing on: subprocess.call([pdftotext, pdf_filename]) the error being:
I have a C program which calls fork() And I have a python script
I have a python script which calls a lot of shell functions. The script
So I have a python script that runs a loop in which it calls
I have a Python script that calls an executable program with various arguments (in
Greetings. I have written a little python script that calls MySQL in a subprocess.
I have installed some python packages which I am able to access using IDLE
I have a python function that makes a subprocess call to a shell script

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.