我如何从 python 中的 subprocess.call 调用多个文件(bash 文件)
how can i call mutiple files(bash files) from subprocess.call in python
#我正在尝试 运行 插件文件夹
中的所有 bash 脚本
import sys,os,subprocess
folder_path=os.listdir(os.path.join(os.path.dirname(__file__),'plugins'))
sys.path.append(os.path.join(os.path.dirname(__file__),'plugins'))
for file in folder_path:
if file == '~':
continue
elif file.split('.')[1]=="sh":
print file
subprocess.call(['./plugins/${file} what'],shell=True,executable='/bin/bash')
it shows error:
bash: /bin/bash: ./plugins/: Is a directory
您需要将 file
变量实际插入到子进程调用字符串中:
subprocess.call(['./plugins/%s what' % file],shell=True,executable='/bin/bash')
#我正在尝试 运行 插件文件夹
中的所有 bash 脚本import sys,os,subprocess
folder_path=os.listdir(os.path.join(os.path.dirname(__file__),'plugins'))
sys.path.append(os.path.join(os.path.dirname(__file__),'plugins'))
for file in folder_path:
if file == '~':
continue
elif file.split('.')[1]=="sh":
print file
subprocess.call(['./plugins/${file} what'],shell=True,executable='/bin/bash')
it shows error:
bash: /bin/bash: ./plugins/: Is a directory
您需要将 file
变量实际插入到子进程调用字符串中:
subprocess.call(['./plugins/%s what' % file],shell=True,executable='/bin/bash')