Subprocess stdout for file, new line missing

I call the subprocess, I want the output of the subprocess to be written to an already open file. I am using the following code:

f1=open('solve.out','w') 
#beginning of the programm writes to this file
f_err = open('mor.err', "w")
arguments=[file.exe,arg1,arg2,...]
p=subprocess.Popen(arguments,stdout=f1, stderr=f_err)
p.wait()
f1.close()
f_err.close()

This works fine as I get real-time output from .exe in my program. However, the outputs are written on one line. As standalone, the output appears with new lines.

I tried universal_newlines or p.communicate () with no success.

edit 1: windows10 Python version 2.7.13

edit 2: Hex file enter image description here

+4
source share
1 answer

Your program seems to detect that the output is being redirected to non-console output.

, , , 6 . , , - , .

2 ( / ), , :

p=subprocess.Popen(arguments,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output,error = p.communicate()
f1.write(output.replace(" "*6,"\n"));
f_err.write(error.replace(" "*6,"\n"));
+1

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


All Articles