如何在Python中运行一个带参数的Bash脚本文件

0 人关注

我想用python来运行以下bash脚本。

sed -n -e '/SCN/,/^\s*$/p' $@ > Junction-Links.txt

bash脚本被保存为ext-jun-links.sh,我想用Python运行它,用文件名代替$@。

我目前正试图使用下面的代码来做这件事。

import subprocess
from subprocess import call
subprocess.run(["./ext-jun-links.sh","NETL1405.TXT"], shell=True)

However, this gives me the error below:

'ext-jun-links.sh' is not recognized as an internal or external command, operable program or batch file.

有什么方法可以解决这个错误吗?在使用PowerShell和以下代码时,bash文件运行正常,所以这不是问题。

bash ext-jun-links.sh 'NETL1405.TXT'
    
python
bash
subprocess
RevolverOshawott
RevolverOshawott
发布于 2021-06-16
1 个回答
Max Turchin
Max Turchin
发布于 2021-06-16
已采纳
0 人赞同

我认为这是因为你试图通过PowerShell执行一个bash脚本。

bash ext-jun-links.sh 'NETL1405.TXT'