Actual meaning of 'shell=True' in subprocess

后端 未结 5 1527
梦毁少年i
梦毁少年i 2020-11-21 05:05

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

In the following codes:

callProcess = subproces         


        
5条回答
  •  别那么骄傲
    2020-11-21 05:42

    An 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")
    What file would you like to display?
    non_existent; rm -rf / # THIS WILL DELETE EVERYTHING IN ROOT PARTITION!!!
    >>> call("cat " + filename, shell=True) # Uh-oh. This will end badly...
    

    Check the doc here: subprocess.call()

提交回复
热议问题