python - 在 Windows 中关闭 Python 中的主程序时,通过子进程传递参数并终止子进程
问题描述
我有两个 Python 文件,文件 1 和文件 2,它们做两个不同的事情。我想一起运行它们。我正在使用 VS2017
文件 1 的伪代码是:
Class A:
foo1():
.
.
foo2();
if variable<30;
#do this
else;
process = subprocess.Popen('py file2.py' ,shell=True,stdin=None, stdout=None, stderr=None, close_fds=True)
#rest of the code for foo2()
if __name__ == "__main__":
A.foo2();
我还想将变量传递给第二个文件。我正在研究类似的东西
variable = input("enter variable)
cmd = ['py file2.py', variable]
subprocess.Popen(cmd ,shell=True,stdin=None, stdout=None, stderr=None, close_fds=True)
我收到一条错误消息:
'"py subproleap.py"' 不是内部或外部命令、可运行程序或批处理文件。
即使我确实传递了变量,我如何让 file2.py 读取它?
任何帮助,将不胜感激。我是python的初学者。
EDIT1:为什么我使用子进程是我希望file2.py在后台运行,一旦满足条件,而主进程在旁边运行。
解决方案
推荐阅读
- uima - 如何在 RUTA 中选择和设置覆盖/覆盖注释作为特征
- vba - 取消保护文档、运行子程序和保护文档时出现 VBA 错误(带有 if/thens 的范围似乎不起作用,但基本 if then 工作)
- reactjs - 为什么 reactDom 不应用 Twig 文件
- angular - 如何在角度模板中迭代联合类型数组
- html - .css 中定义的类背景未显示在网页上。无法识别图像的路径。为什么?
- javascript - 木偶怪的行为
- p5.js - 如何使用 P5js 中触摸对象的 X 和 Y 值?
- sql - 最大行大小超过允许的最大值 8060 字节,我无法将列从 char 转换为 nvarchar
- c# - 更改不可变字段 _id 错误 Mongo DB .net
- java - 如何在java中将拉丁字母转换为英文对应?