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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:09:33+00:00 2026-05-31T23:09:33+00:00

I am trying to execute, from a python3 script, Unix commands that looks like

  • 0

I am trying to execute, from a python3 script, Unix commands that looks like that:

mycommand `cmd_giving_a_path`/file

So I am using the subprocess.Popen function. But whatever I tried, the subprocess doesn’t evaluate the command between backquotes.
Here is what I tried:

>>> subprocess.Popen(['echo', 'toto'])
<subprocess.Popen object at 0x2a98df1c50>
>>> toto

Fine!

subprocess.Popen(['echo', 'toto', '`ls`'])
<subprocess.Popen object at 0x2a98df1d50>
>>> toto `ls`

Fine too!

>>> subprocess.Popen(['echo', 'toto', '`ls`'], shell=True)
<subprocess.Popen object at 0x2a98df1d90>

I don’t understand this one: I have no output at all.
With this command I expected that a shell is spawned and receive the command:

echo toto `ls`

But obsviously, I am wrong!

Could someone help with that?

Thank you!

PS: For those who may ask ‘why do you need this?’ the answer is:
because the options for the commands are read from an input file that may contains this kind of syntax.

  • 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-31T23:09:35+00:00Added an answer on May 31, 2026 at 11:09 pm

    From the pydoc documentation for subprocess: On UNIX, with shell=True: If args is a string, it specifies the command string to execute through the shell. If args is a sequence, the first item specifies the command string, and any additional items will be treated as additional shell arguments.

    I.e., you were telling subprocess to run the following command:

    bash -c 'echo' 'toto' '`ls`'
    

    As ephemient pointed out, what you really want to run is:

    bash -c 'echo toto `ls`'
    

    which you can do with either of:

    subprocess.Popen('echo toto `ls`', shell=True)
    subprocess.Popen(['echo toto `ls`'], shell=True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to execute a file with Python commands from within the interpreter. I'm
I'm trying to start a PowerShell script from python like this: psxmlgen = subprocess.Popen([r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe',
I'm using ASP.net and I'm trying to execute a webmethod from jquery. I have
i am trying to execute the records that have TotalTime null value from the
I'm trying to write a python script that does the following from within a
I am trying to make an script that will every second read string from
I am trying to execute the following code in Python import os,subprocess from glob
I am trying to execute ajax method from Dialog, but its not getting executed.
I`m trying to execute linux commant 'cat' from java code, but it does not
I am trying to execute a stored procedured from a linked database in MS

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.