如何在pypsexec中获取长时间运行命令的结果?

问题描述 投票:0回答:1

我正在使用 pypsexec 连接到远程 Windows 计算机。我必须找到具有特定扩展名的文件列表。这就是我现在正在做的事情。

command = "dir /b/s *.py"
client.run_executable("cmd.exe", arguments=f"/c {command}", asynchronous=True)

当我没有使用异步参数时,一开始我没有收到任何响应。阅读文档后,我可以看到长时间运行的任务(例如我的任务)应该使用此参数。但是,它没有提供有关如何在作业完成后获取输出的明确说明。

提前致谢!

python windows psexec
1个回答
0
投票

这是因为你无法获取输出。请参阅https://github.com/jborean93/pypsexec/blob/master/pypsexec/client.py#L436-L466

if not interactive and not asynchronous:
    [...] # Here is where stdout and stderr is set
else:
    stdout_out = None
    stderr_bytes = None

[...] # Here is some code that doesn't change stdout_out or stderr_bytes

return stdout_out, stderr_bytes, return_code

正如您所见,使用

asynchronous=True
时,stdout 和 stderr 将始终为
None

© www.soinside.com 2019 - 2024. All rights reserved.