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

后端 未结 7 397
轮回少年
轮回少年 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:26

    I just got this error on Mac OS, while trying to call a one-line script using subprocess.call. The script ran fine when called from the command line. After adding the shebang line #!/usr/bin/env sh, it also ran fine via subprocess.call.

    It appears, while the shell has a default executor for text files marked executable, subprocess.Popen does not.

提交回复
热议问题