简体   繁体   English

PyInstaller + subprocess.check_output + Windows 计划任务

[英]PyInstaller + subprocess.check_output + Windows Scheduled task

this is a topic for somebody who may face similar thing in future.对于将来可能面临类似事情的人来说,这是一个话题。 Once you try to schedule task in Windows using executable that was compiled with PyInstaller with option -noconsole and trying to use subprocess.check_output it does not work一旦您尝试使用使用 PyInstaller 编译并带有选项 -noconsole 的可执行文件在 Windows 中安排任务并尝试使用 subprocess.check_output 它不起作用

Funny thing that if you call .exe directly then it works perfectly fine.有趣的是,如果您直接调用 .exe 则它可以正常工作。 However if you schedule a task or try to wrap execution into batch like:但是,如果您安排任务或尝试将执行包装成批处理,例如:

C:\git\backend.exe -p C:\Users\settings.json

then it fails without any error code.然后它失败而没有任何错误代码。
Only thing one can found is in tasks event log is error code: 2147942401只有在任务事件日志中可以找到错误代码:2147942401

solution will be to explicitly specify Popen with stdin, out, err解决方案是使用 stdin、out、err 显式指定 Popen

p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = p.stdout.read().decode('utf-8')
p.communicate()  

I found similar topics but just want to explicitly mention that by default command call or .exe double click it works but not from scheduled task我发现了类似的主题,但只想明确指出,默认情况下命令调用或 .exe 双击它可以工作,但不能从计划任务

Inspired from here:灵感来自这里:
Pyinstaller issue with subprocess.check_output subprocess.check_output 的 Pyinstaller 问题
Pyinstaller subprocess.check_output error Pyinstaller subprocess.check_output 错误
pyinstaller on Windows with --noconsole simply won't work 带有 --noconsole 的 Windows 上的 pyinstaller 根本不起作用

PS I always look for better solutions, if you have one, please suggest! PS我一直在寻找更好的解决方案,如果你有一个,请提出建议!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM