我有一个脚本 abc.sh,其中包含带标志的命令列表。例子
//abc.sh
echo $FLAG_name
cp $FLAG_file1 $FLAG_file2
echo 'file copied'
我想通过 python 代码执行这个脚本。说
//xyz.py
name = 'FUnCOder'
filename1 = 'aaa.txt'
filename2 = 'bbb.txt'
subprocess.call([abc.sh, name, filename1, filname2], stdout=PIPE, stderr=PIPE, shell=True)
这个电话不工作。
还有哪些选择?
shell 脚本文件也位于其他目录中。我希望输出进入日志。
原文由 Rishabh Agarwal 发布,翻译遵循 CC BY-SA 4.0 许可协议
通常你想使用
Popen
因为你之后有过程控制。尝试: