Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get all of the output from my .exe using subprocess and Popen?
    primarykey
    data
    text
    <p>I am trying to run an executable and capture its output using <code>subprocess.Popen</code>; however, I don't seem to be getting all of the output. </p> <pre><code>import subprocess as s from subprocess import Popen import os ps = Popen(r'C:\Tools\Dvb_pid_3_0.exe', stdin = s.PIPE,stdout = s.PIPE) print 'pOpen done..' while: line = ps.stdout.readline() print line </code></pre> <p>It prints two line less than the original exe file when opened manually.</p> <p>I tried an alternative approach with the same result:</p> <pre><code>f = open('myprogram_output.txt','w') proc = Popen('C:\Tools\Dvb_pid_3_0.exe ', stdout =f) line = proc.stdout.readline() print line f.close() </code></pre> <p>Can anyone please help me to get the full data of the exe?</p> <h2>As asked by Sebastian:</h2> <p>Original exe file last few lines o/p:</p> <p>-Gdd : Generic count (1 - 1000)</p> <p>-Cdd : Cut start at (0 - 99) -Edd : Cut end at (1 - 100)</p> <p>Please select the stream file number below:</p> <p>1 - .\pdsx100-bcm7230-squashfs-sdk0.0.0.38-0.2.6.0-prod.sao.ts</p> <p>The o/p I get after running:</p> <pre><code>-P0xYYYY : Pid been interested </code></pre> <p>-S0xYYYY : Service ID been interested<br> -T0xYYYY : Transport ID been interested<br> -N0xYYYY : Network ID been interested<br> -R0xYYYY : A old Pid been replaced by this PID<br> -Gdd : Generic count (1 - 1000) </p> <p>So we can see some lines missing. I have to write 1 and choose value after please select the fule number below appears.</p> <p>I tried to use ps.stdin.write('1\n'). It didn't print the value in the exe file</p> <p>New code:</p> <pre><code>#!/usr/bin/env python from subprocess import Popen, PIPE cmd = r'C:\Tools\Dvb_pid_3_0.exe' p = Popen(cmd, stdin=PIPE, stdout=None, stderr=None, universal_newlines=True) stdout_text, stderr_text = p.communicate(input="1\n\n") print("stdout: %r\nstderr: %r" % (stdout_text, stderr_text)) if p.returncode != 0: raise RuntimeError("%r failed, status code %d" % (cmd, p.returncode)) </code></pre> <p>Thanks Sebastien. I am able to see the entire output but not able to feed in any input with the current code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload