Python subprocess losing 10% of a program's stdout

I have a program that needs to be called as a subprocess with python. The program has been written in java. yeah, i know... anyway, I need to capture all of the output from said program. Unfortunately, when I call subprocess.popen2 or subprocess.Popen with communicate[0], I'm losing around 10% of the output data when I'm using a subprocess.PIPE assigned to stdout AND when i'm us

Python子进程失去了程序标准输出的10%

我有一个程序,需要被称为与Python的子进程。 该程序已用java编写。 是的,我知道... 无论如何,我需要捕获所有程序的输出。 不幸的是,当我使用通信[0]调用subprocess.popen2或subprocess.Popen时,当我使用子进程时,输出数据的大约10%会丢失。分配给stdout的AND会在我使用文件描述符(从开放返回)分配给标准输出。 子进程中的文档非常明确,使用subprocess.PIPE是挥发性的,如果你想捕获一个子进程的所有输出。

Broken Pipe from subprocess.Popen.communciate() with stdin

I'm having a strange issue when using subprocess.Popen.communicate(). For background, I want to execute an application from my python script. When I run the program from the command line, I do it like this (UNIX): $ echo "input text" | /path/to/myapp From my script, I also want to pipe the input into the application. So, I tried the following. But I get a "broken pipe" error

subprocess.Popen.communciate()与stdin一起损坏的管道

使用subprocess.Popen.communicate()时出现一个奇怪的问题。 为了背景,我想从我的python脚本执行一个应用程序。 当我从命令行运行程序时,我这样做(UNIX): $ echo "input text" | /path/to/myapp 从我的脚本中,我也想将输入输入到应用程序中。 所以,我尝试了以下。 但是当我尝试使用communic()发送输入时,出现“断开的管道”错误: >>> cmd = ['/path/to/myapp'] >>> p = subprocess.Popen(cmd, stdout=subproc

Popen subprocess.PIPE and its uses

I know that this question may have been asked a lot but I am still not really getting it. Reading from this related link, I can understand why there is a need to add stdout=subprocess.PIPE at the end of the sentence so that the output result can be used into the next Popen. Tried looking online, but I garner little to no knowledge about it as the ones I found are in the form of a documentation

Popen子进程.PIPE及其用途

我知道这个问题可能已经被问了很多,但我还没有真正得到它。 从这个相关的链接中读取,我可以理解为什么需要在句子末尾添加stdout=subprocess.PIPE ,以便输出结果可以用于下一个Popen。 尝试在网上寻找,但我几乎没有获得关于它的知识,因为我发现它们是以文档的形式出现的。 但是如果我不使用输出,是否真的有必要把stdout=subprocess.PIPE放在最后? 我试着用它来执行它,但它仍然给我预期的结果。 因此,不论subproc

Subshell in python subprocess

Within a python script I need to launch a command such as kill $(ps aux | grep httpd | awk '{print $2}') Using subprocess I have tried to split the command using a function from https://stackoverflow.com/a/29755431/1355628) The function is fine with simple commands with pipe but unfortunately with the one above it does not seem to work (the return code seems to be completely random...) Than

在python子流程中的子shell

在一个python脚本中,我需要启动一个命令如 kill $(ps aux | grep httpd | awk '{print $2}') 使用子进程我试图使用一个函数从https://stackoverflow.com/a/29755431/1355628拆分命令) 这个函数对于使用管道的简单命令来说很好,但不幸的是,上面的代码似乎并不奏效(返回代码似乎完全是随机的) 感谢提前 subprocess.run采用可选的shell=True参数,它将在子shell中运行你的命令。 如果您正在处理用户输入,请阅读安全

Unknown argument:

I am getting Unknown argument: | when using the below script and I'm not sure why it doesn't like the | . I am on Windows, with Python 2.7.11: import subprocess from subprocess import Popen, PIPE, STDOUT import time command = 'VSPipe.exe --y4m script.vpy - | ffmpeg.exe -f yuv4mpegpipe -i - -c:v prores -an output.mov' process1 = Popen(command, stderr=PIPE, shell=False) while True:

未知参数:

我得到Unknown argument: | 当使用下面的脚本时,我不确定它为什么不喜欢| 。 我在Windows上使用Python 2.7.11: import subprocess from subprocess import Popen, PIPE, STDOUT import time command = 'VSPipe.exe --y4m script.vpy - | ffmpeg.exe -f yuv4mpegpipe -i - -c:v prores -an output.mov' process1 = Popen(command, stderr=PIPE, shell=False) while True: line = process1.stderr.readline().decode('

Python: piping Requests image argument to stdin

I am trying to send arguments to a subprocess' stdin. In my case, it is an image downloaded with Requsts. Here is my code: from subprocess import Popen, PIPE, STDOUT img = requests.get(url, stream=True) i = img.raw.read() proc = subprocess.Popen(['icat', '-'], stdout=PIPE, stdin=PIPE, stderr=STDOUT) proc.communicate(i) #proc.stdin.write(i) # I tried this too Unfortunately, the subprocess

Python:管道请求图像参数为stdin

我正在尝试将参数发送到子进程的标准输入。 在我的情况下,它是一个与Requsts一起下载的图像。 这是我的代码: from subprocess import Popen, PIPE, STDOUT img = requests.get(url, stream=True) i = img.raw.read() proc = subprocess.Popen(['icat', '-'], stdout=PIPE, stdin=PIPE, stderr=STDOUT) proc.communicate(i) #proc.stdin.write(i) # I tried this too 不幸的是,子进程没有任何作用,我也没有任何错误。

Using subprocess for socat in Python

I am trying to use the subprocess to execute a command socat . It just echos the command as 'show stat | socat unix-connect:/users/viperias/Applications/haproxy.stat stdio' 'show stat | socat unix-connect:/users/viperias/Applications/haproxy.stat stdio' rather than printing the output of the command. It perfectly works for the other commands. Am I missing something? def m

在Python中使用socat的子进程

我正在尝试使用subprocess来执行命令socat 。 它只是将命令作为'show stat | socat unix-connect:/users/viperias/Applications/haproxy.stat stdio' 'show stat | socat unix-connect:/users/viperias/Applications/haproxy.stat stdio'而不是打印命令的输出。 它完美适用于其他命令。 我错过了什么吗? def main(): cmd = "echo show stat | socat unix-connect:/users/viperias/Applications

How do subprocess.Popen pipes work in Python?

I am fully aware of the existence of related questions, but all of them are very fuzzy and fail to clearly explain what is going on every step of the way. The examples provided are often not tested and provide no information on how to adapt them to different scenarios. Here are the questions as well as Python's documentation: How do I use subprocess.Popen to connect multiple processes by

subprocess.Popen管道如何在Python中工作?

我完全意识到相关问题的存在,但他们都非常模糊,并且未能清楚地解释每一步的进展。 所提供的例子通常没有经过测试,并且没有提供关于如何使它们适应不同场景的信息。 以下是问题以及Python的文档: 如何使用subprocess.Popen通过管道连接多个进程? 用管道连接几个Popen命令 https://docs.python.org/2/library/subprocess.html#popen-objects 这基本上是我想要实现的,但在Python中: curl http://asdf.com/89asdf.g

invoking pipe command with Popen in Python

What is the correct way to invoke a command containing multiple pipes to Popen so that its output can be read? I tried: Popen(shlex.split("mycmd arg1 | mysecondcmd - | thirdcmd -", stdout=PIPE)") But I don't believe shlex.split is right here. What's the correct syntax? You have a few options -- You can pass shell=True : Popen('command1 | command2 | command3',shell=

在Python中用Popen调用pipe命令

调用包含Popen多个管道的命令以便读取其输出的正确方法是什么? 我试过了: Popen(shlex.split("mycmd arg1 | mysecondcmd - | thirdcmd -", stdout=PIPE)") 但我不认为shlex.split就在这里。 什么是正确的语法? 你有几个选项 - 你可以传递shell=True : Popen('command1 | command2 | command3',shell=True) 或者,您可以将它分解成一堆Popen调用,将它们的stdout挂接到文档中演示的下一个Popen的std

Difference Between stdout=subprocess.PIPE and stdout=PIPE

So The title pretty much explains my question. What is the difference between stdout=subprocess.PIPE and stdout=PIPE? Both come from the subprocess module, but why would you use one over the other? How do you use stdout=PIPE? Ie capture the output? Or print it to the screen? I only know how to redirect it with subprocess.PIPE. eg import subprocess from subprocess import PIPE p = subproce

stdout = subprocess.PIPE和stdout = PIPE之间的区别

所以标题几乎解释了我的问题。 stdout = subprocess.PIPE和stdout = PIPE有什么区别? 两者都来自子流程模块,但为什么要使用另一个呢? 你如何使用stdout = PIPE? 即捕获输出? 或者打印到屏幕上? 我只知道如何用subprocess.PIPE重定向它。 例如 import subprocess from subprocess import PIPE p = subprocess.Popen(['samtools', 'view', 'bamfile.bam'], stdout=PIPE) from subprocess import PIPE 使subprocess