Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Subprocess.Popen仅第二次运行_Python_Windows_Subprocess_Popen - Fatal编程技术网

Python Subprocess.Popen仅第二次运行

Python Subprocess.Popen仅第二次运行,python,windows,subprocess,popen,Python,Windows,Subprocess,Popen,我有一个启动控制器,它运行一个boot.py文件,该文件包含在我试图部署的每个工具的每个文件夹中。我希望我的启动控制器同时运行所有这些启动文件。配置文件具有所需的工具名称和版本,这有助于生成到boot.py的路径 def run_boot(): config_file = get_config_file() parse_config_file.init(config_file) tools = parse_config_file.get_tools_to_deploy()

我有一个启动控制器,它运行一个
boot.py
文件,该文件包含在我试图部署的每个工具的每个文件夹中。我希望我的启动控制器同时运行所有这些启动文件。配置文件具有所需的工具名称和版本,这有助于生成到
boot.py
的路径

def run_boot():
    config_file = get_config_file()
    parse_config_file.init(config_file)
    tools = parse_config_file.get_tools_to_deploy()
    #tools is now a list of tool names
    top_dir = os.getcwd()
    for tool in tools:
        ver = parse_config_file.get_tool_version(tool).strip()
        boot_file_path = "{0}\\Deploy\\{1}\\{2}".format(os.getcwd(),tool,ver)
        try:
            subprocess.Popen('boot.py', shell=True,  cwd=boot_file_path)
        except:
            print ("{0} failed to open".format(tool))
        print(tool, boot_file_path)
        os.chdir(top_dir)

我第一次运行它时,
打印(工具,启动文件路径)
会执行,但进程不会执行。第二次运行时,进程确实会打开。我找不到这样的理由

为什么在Python子进程中运行Python,为什么不需要shell时运行Python?为什么有效地运行当前目录?也许您对目录的理解才是真正的问题。@tripleee当子进程运行时,将
cwd
设置为一个值,它会将当前工作目录切换为该值,然后再也找不到其他目录。另外,我不明白您的意思,为什么我要在python子流程中运行python?这是一个我需要运行的脚本,更好的方法是什么?另外,路径应该通过
os.path.join
连接,而不是一般的字符串格式。Windows很奇怪,有时很可怕,但在另一个目录中运行子进程不应该改变父进程的cwd,即使在Windows上也是如此,据我所知。