【问题标题】:how can i call mutiple files(bash files) from subprocess.call in python我如何从 python 中的 subprocess.call 调用多个文件(bash 文件)
【发布时间】:2016-08-08 09:24:53
【问题描述】:

#我正在尝试运行插件文件夹中的所有 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

【问题讨论】:

    标签: python bash subprocess


    【解决方案1】:

    您需要将file 变量实际插入到子进程调用字符串中:

    subprocess.call(['./plugins/%s what' % file],shell=True,executable='/bin/bash')
    

    【讨论】:

      猜你喜欢
      • 2020-03-29
      • 2012-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多