Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使python子进程stdout和stderr显示在Visual Studio中';什么是输出窗口?_Python_Visual Studio - Fatal编程技术网

如何使python子进程stdout和stderr显示在Visual Studio中';什么是输出窗口?

如何使python子进程stdout和stderr显示在Visual Studio中';什么是输出窗口?,python,visual-studio,Python,Visual Studio,我切换到用于VisualStudio(VS2012)的Python工具,我正在尝试启动并运行我的项目。我遇到了一个问题,子进程的stdout没有显示在VisualStudio输出窗口中。我创建了一些示例代码来说明这个问题 test_console.py import os import subprocess print 'printed from the main process' command = 'python ' + os.path.join(os.getcwd(),'test_con

我切换到用于VisualStudio(VS2012)的Python工具,我正在尝试启动并运行我的项目。我遇到了一个问题,子进程的stdout没有显示在VisualStudio输出窗口中。我创建了一些示例代码来说明这个问题

test_console.py

import os
import subprocess
print 'printed from the main process'
command = 'python '  + os.path.join(os.getcwd(),'test_console_sub.py')
subprocess.call(command)
测试控制台

print 'printed from a subprocess'
执行test_console.py时显示的python控制台正确地显示了这两个文件的输出

输出窗口缺少子流程打印语句

以下是一些相关设置

如何使子流程打印语句显示在Visual Studio输出窗口中?理想情况下,输出窗口将与python控制台窗口完全相同。

您不能。 我以前找过这个,什么也没找到。如果我错了,请纠正我

尝试改用文本编辑器和python控制台

作为一种解决方法(参见AnojiRox的答案),您可以从子进程捕获stdout和stderr,然后从主进程打印它,但由于中所述的死锁问题,您需要使用Popen和its


哇!在我短暂的一生中,我浪费了12个小时在谷歌上搜索这个。。。你可以用7行代码来完成。。
import os
import subprocess

print 'printed from the main process'
command = ['python', os.path.join(os.getcwd(), 'test_console_sub.py')]
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
print stdout
print stderr