首頁  >  文章  >  後端開發  >  如何在 pypsexec 中取得長時間運行命令的結果?

如何在 pypsexec 中取得長時間運行命令的結果?

WBOY
WBOY轉載
2024-02-12 11:30:051238瀏覽

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

問題內容

我正在使用 pypsexec 連接到遠端 windows 電腦。我必須找到具有特定擴展名的文件列表。這就是我現在正在做的事情。

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

當我沒有使用非同步參數時,一開始我沒有收到任何回應。閱讀文件後,我可以看到長時間運行的任務(例如我的任務)應該使用此參數。但是,它沒有提供有關如何在作業完成後取得輸出的明確說明。

提前致謝!


正確答案


這是因為你無法得到輸出。請參閱 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

以上是如何在 pypsexec 中取得長時間運行命令的結果?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:stackoverflow.com。如有侵權,請聯絡admin@php.cn刪除