我正在开发一个Python脚本远程通过SSH的树莓派与VSCode。
在脚本中,我想在一个分离的子进程中运行一个命令,
subprocess.Popen('command')
该命令在stdout上生成输出,我希望将其显示在第二个终端中,以便进行调试。
我使用哪个python命令最好。
感谢您的帮助!
发布于 2021-01-14 00:48:41
您可以使用logging模块将该信息写入文件,也可以使用.call()函数,如下所示:
from subprocess import PIPE, run
cmd = [command, "-arg1", "-arg2"]
result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(result.stdout)
print(result.stderr)这将打印输出。
发布于 2021-01-19 03:04:08
我认为应该使用libtmux (https://libtmux.git-pull.com/quickstart.html#quickstart和https://libtmux.git-pull.com/api.html)
您实际上可以在多个并行的、独立的终端会话中发送和接收线路!
对于我需要在检查服务器状态的同时与websocket服务器对话,这对我来说是完美的解决方案。它运行在VSCode中,用于编码期间的调试目的,以及部署后用于远程修复问题的常规SSH会话中。
致以最好的问候,LeFish
https://stackoverflow.com/questions/65706163
复制相似问题