Capturing console output that is not written to stdout, stderr?

I have a windows application called pregeocode (we have no source), this program basically writes geocoding to the input file. This program does not actually write anything to the console if there is an error. This program, as a rule, is called from a small Python program (it processes arguments, etc. And does everything that is needed for preprocessing).

We check to see if it worked if an output file was created (it always returns 0, no matter what). However, when it does not work, the subprocess indicates that nothing was printed in stderr or stdout. (It processes about a hundred or so successfully, since only one of them is bad, but I would like to see what causes the error)

The little python script calls the application through subprocess.Popen:

argslist = [r'C:\workspace\apps\pregeocode.exe', '-in', inputfilename, '-out', outputfilename, '-gcp', gcp_file]
p = subprocess.Popen(argslist, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
print str(p.communicate())

Gives output:

('', '')

However, if I run the program manually using the same arguments via cmd, I get the output:

45 IMAGE_EXTENT_TOO_SMALL

(There are about 60 odd different error messages, 45 indicates the error number)

Using the shell = True argument doesn't change anything, and I can't find anything online about this issue. The actual exe is what was done in the house a long time ago, and we lack the source code for it, so I don’t see how it prints messages.

So, why is it impossible to handle the stdout or stderr subprocess?

EDIT

os.system(" ".join(argslist))

correctly prints the error message:

45 IMAGE_EXTENT_TOO_SMALL

EDIT 2

, ERDAS. stdout/stderr . "CON".

+3
2

stdout, stderr, , Windows /dev/tty, . Unix pty.openpty, , , Python Windows. Expect for Windows.

+5

python 2.5 2.6? subprocess.check_output stderr stdout:

out_err = subprocess.check_output(argslist, stderr=subprocess.STDOUT)

out_err , , , , stdout stderr , ( unix- ):

fout = open('fout', 'w')
ferr = open('ferr', 'w')    
p = subprocess.Popen(argslist, stdout=fout, stderr=ferr)
p.wait()
fout.close()
ferr.close()
0

Source: https://habr.com/ru/post/1769401/


All Articles