Is this the right way to run a shell script inside Python?

后端 未结 7 391
轮回少年
轮回少年 2021-01-07 16:37
import subprocess
retcode = subprocess.call([\"/home/myuser/go.sh\", \"abc.txt\", \"xyz.txt\"])

When I run these 2 lines, will I be doing exactly t

7条回答
  •  礼貌的吻别
    2021-01-07 17:21

    Change the code to following:

    retcode = subprocess.call(["/home/myuser/go.sh", "abc.txt", "xyz.txt"], shell=True,)
    

    Notice "shell=True"

    From: http://docs.python.org/library/subprocess.html#module-subprocess

    On Unix, with shell=True: If args is a string, it specifies the command string to execute through the shell. This means that the string must be formatted exactly as it would be when typed at the shell prompt.

提交回复
热议问题