如何处理python参数传递而不是执行子进程调用

2024-10-01 02:23:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用一个包,Automater(https://github.com/1aN0rmus/TekDefense-Automater),包的开发人员使用参数来运行脚本

python Automater.py {params}

但我正试图将其包含到我自己的应用程序中,并试图避免修改他的代码。是否可以通过我的应用程序运行Automater

我试过了

subprocess.call(["python", "automater/Automater.py", "params"]) 

但这似乎连自动装置都没有。有人能指出我做错了什么吗

层次结构是:

myprogram.py
automater/Automater.py
__init__.py

我做了一些修改,现在改做这个

p = Popen(["python", "automater/Automater.py", query], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate(b"input data that is passed to subprocess' stdin")
rc = p.returncode
print output, err, rc

但这只是为错误代码打印0,没有其他要调试的消息

编辑:

经过进一步的实验,我发现我必须在automater的目录中,automater.py才能正常运行,有没有办法在Python中做到这一点?i、 e.移动到目录->;run命令


Tags: pyhttpsgithub目录comoutputstdinparams