This question already has answers here:

Can I use an alias to execute a program from a python script
(5个答案)
我希望你们能帮我解决这个问题,因为我真的被困在…我试图从python中执行一个程序,但由于某种原因,它不起作用。脚本位于:
path/to/teqc

我已将此行添加到.bashrc文件中:
alias teqc='path/to/teqc'

当我跑的时候
teqc -tr d input >output
在终端上它工作正常…但是,如果我在python程序上运行它,它会显示:
sh: teqc: command not found

我在python上使用的代码是:
os.system('teqc -tr d input >output')

我试着用
subprocess.Popen('teqc -tr d input >output', shell=True, executable="/bin/bash")

但唯一的结果是将错误消息更改为
/bin/bash: teqc: command not found

任何帮助都将不胜感激:)
P.D.我忘了指定,操作系统是Fedora21

最佳答案

我建议创建一个到您的程序的符号链接。

ln -s /path/to/teqc /usr/bin/teqc

关于python - Python无法使用sh或bash执行终端脚本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27951765/

10-11 23:15
查看更多