我正在调用一个子进程,我希望将子进程输出写入一个已经打开的文件。我正在使用以下代码:
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()
Run Code Online (Sandbox Code Playgroud)
这很好用,因为我从程序中的 .exe 获得实时输出。但是,输出都写在一行中。作为独立的,输出显示新行。
我尝试了 Universal_newlines 或 p.communicate() 没有成功。
编辑 1:windows10 Python 版本 2.7.13
我构建了我的 .so 文件:
go build -buildmode=plugin -o test.so
Run Code Online (Sandbox Code Playgroud)
并使用 Goland 运行调试,然后出现错误:
Error running agent: could not initialize input inputs.plugin_input: plugin.Open("./plugins_lib/test1"): plugin was built with a different version of package runtime/internal/sys
Run Code Online (Sandbox Code Playgroud)
但是我可以在我的终端中构建我的主程序,它会运行良好。