cost 84 ms
实时打印 stderr 和 stdout 的子进程

[英]subprocess to print stderr and stdout in real-time

假设我有这个程序printer.py : 它打印到 stdout 和 stderr 以产生: 我想在另一个 python 脚本runner.py中执行printer.py ,并实时打印 stderr 和 stdout。 以下版本的runner.py不起作用: 因为它首先实时打印 stderr 行,然 ...

如何获取外部可执行文件的输入和 Output?

[英]How to get the Input and Output of an external Executable?

我想深入挖掘自动化,但没有找到任何关于从任何可执行文件获取信息的信息。 我想要的是通过 Python 启动一个 exe,这样 python 就可以看到当我按下一个按钮或在该外部程序中执行其他操作时会发生什么。 有了给定的数据,我想自动化外部程序并给它数据来按下它自己的按钮。 就像 silenium ...

将参数传递给 subprocess.Popen

[英]Passing args to subprocess.Popen

需要调用grep from python grep 命令: grep -B 5 -A 5 "make.*Error|Error-" file 尝试了 escaping 的各种组合,正则表达式使其与 subprocess.Popen 一起使用 我是否缺少某种转义字符以将该正则表达式正确传递给 gre ...

在进程 python 中运行 function 时捕获实时 `stdout` 和 `stderr`

[英]Capture real time `stdout` and `stderr` when run a function in a process python

我有一个 python function 并希望将它作为一个单独的进程运行,并带有multiprocessing package。 然后使用以下脚本将其作为单独的进程运行: 现在,我需要捕获上述过程的实时stdout和stderr 。 有没有什么办法像: 但是我需要传递 function 而不是使 ...

如何从 python 运行 GAMS?

[英]How to run GAMS from python?

我正在尝试从 python 文件运行 GAMS 文件。 我在 macbook 上使用 vscode。 到目前为止,我已经能够使用subprocess从 Python 打开所需的 GAMS 文件。 为此,我使用了以下代码块: 但是,它只是打开 GAMS 文件而不执行它。 我需要执行 GAMS 文件, ...

如果以不同的方式调用相同的 python 命令需要不同的时间

[英]Same python commands take different time if called in different ways

我有一些数据(字节)表示来自后台运行的可执行文件的 pyzmq 套接字的 png 图像。 我使用以下命令将它们转换为 numpy 数组decoded = np.asarray(im.open(io.BytesIO(data))) 当我从命令行执行此操作时,这行代码的运行时间不到一毫秒(也通过 pyt ...

Python:subprocess.Popen() 返回 None

[英]Python: subprocess.Popen() returns None

我需要使用 args 执行 CLI 二进制文件,使进程保持活动状态并在整个 python 脚本中运行多个命令。 所以我通过以下方式使用 Python 和 subprocess.Popen() :from subprocess import Popen, PIPE cmd = ["/full/pa ...

如何在不引用当前 virtualenv 的情况下在子进程中运行 poetry install?

[英]How do I run poetry install in a subprocess without reference to the current virtualenv?

我正在用我们拥有的命令行工具编写一些自动设置代码。 此命令行工具随 poetry 一起安装,因此当有人调用命令行工具时,它来自 poetry 设置的虚拟环境。 我试图调用的命令是poetry install for another directory 。 我希望此命令为其他目录创建一个新的 vir ...

ssh-keygen 为空 output,在 macOS Ventura 13.1 上的 python3.10 中带有 subprocess.run 和 os.system

[英]ssh-keygen empty output with subprocess.run and os.system in python3.10 on macOS Ventura 13.1

我一直在尝试 output 使用 python 和“子进程”库从 ssh-keygen (CLI) 生成的签名公钥。 我还尝试了具有相同结果的“os”库。 我真的很想了解为什么它没有按照我的意愿进行:像我期望的那样在屏幕上显示“ssh-keygen -Lf {keyfile}”的 output。 ...

Python 中 subprocess.run 的异常处理

[英]Exception Handling with subprocess.run in Python

我正在尝试创建一个 function,它可以运行任何 shell 命令并返回该命令的标准输出,而不必担心可能引发的任何异常。 当使用xyz testing等不正确的命令测试下面编写的代码时,我得到的是FileNotFoundError而不是CalledProcessError ,即使当我在 shel ...

为什么这个 p.stdin.write 不起作用?

[英]Why does this p.stdin.write is not working?

谢谢,因为命令,我能够绕过那一步,但实际问题是这一步。 此步骤的文档中没有给出命令。 [1]我添加了一个菜单选项的示例,例如我想要 select 力场编号 4,因此,当我执行 subprocess.call subprocess.call[path,4]时,它会给我一个错误作为路径文件将被重新调 ...

Python 子进程调用 output 超时

[英]Python subprocess call with output and timeout

总结:我想从 Python(3.6 版)启动一个外部进程,非阻塞地轮询结果,并在超时后终止。 详细信息:有一个带有 2 个“坏习惯”的外部进程: 它在未定义的时间后打印出相关结果。 它打印出结果后不会停止。 示例:也许以下简单应用程序大部分类似于要调用的实际程序( mytest.py ;源代码不可用 ...

使复杂系统命令适应 subprocess.run()

[英]Adapting a Complex System Command to subprocess.run()

我正在编写一个 Python3 脚本,它必须在我的 Ubuntu 20.04.5 LTS 机器上运行这个系统命令: 当我手动将此命令粘贴到服务器的命令行时,该命令运行良好。 现在我需要我的 Python 脚本来执行它。 感谢这样的帖子,我相信subprocess.run()命令应该在这里工作。 ...

Python - 带有 creationflags (0x00000008) 的子进程 - 进程结束后如何获得 output? (视窗)

[英]Python - subprocess with creationflags (0x00000008) - How to get output after process ends? (Windows)

我写了一个 Python 脚本来运行属于第 3 方程序的终端命令。 这个脚本基本上成功地运行了命令。 但是,我想打印 output 但process.stdout.readlines()打印了一个空列表。 由于第 3 方程序的终端命令,我需要使用 creationflags 运行子进程。 我也试过 ...

摆脱子流程中的额外打印 Python

[英]Getting rid of extra printing in subprocess Python

我正在尝试使用 Linux 中的 subprocess.run() 打印我的 ip 地址。因此,我编写了以下代码: 它在终端中给了我 Ip 地址“192.168.1.103”,但我写了“print(ip)”,它给了我:“CompletedProcess(args=["ifconfig | grep ...


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