我有一个脚本说abc.sh其中有带有标志的命令列表。 示例如何通过python执行shell脚本
//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脚本文件位于其他目录中。我希望输出进入日志。
有你使用[shutls(http://docs.python.org/2/library/shutil.html),而不是一个bash脚本考虑。试试'shutils.copyfile' – 2013-04-23 23:17:50
这里使用'shell = True'是错误的并且会引发错误。 – 2013-04-24 15:27:00