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

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

    Yes, that's perfectly fine if all you're doing is calling the shell script, waiting for it to complete, and gathering its exit status, while letting its stdin, stdout, and stderr be inherited from your Python process. If you need more control over any of those factors, then you just use the more general subprocess.Popen, but otherwise what you have is fine.

提交回复
热议问题