Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I am calling different processes with the subprocess module. However, I have a question.

In the following codes:

callProcess = subprocess.Popen(['ls', '-l'], shell=True)

and

callProcess = subprocess.Popen(['ls', '-l']) # without shell

Both work. After reading the docs, I came to know that shell=True means executing the code through the shell. So that means in absence, the process is directly started.

So what should I prefer for my case - I need to run a process and get its output. What benefit do I have from calling it from within the shell or outside of it.

1 Answer

0 votes
by (106k points)

You can understand the actual meaning of ‘shell=True’ in subprocess by below-mentioned example where things could go wrong with Shell=True is shown here:-

>>> from subprocess import call 

>>> filename = input("What file would you like to display?\n") 

>>> call("cat " + filename, shell=True) 

Related questions

0 votes
1 answer
asked Oct 8, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 5, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
+1 vote
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...