【发布时间】:2016-11-17 18:59:33
【问题描述】:
我想运行用 Python 编写的脚本并从中获取所有输出。 这是我的cpp代码
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
QString exe = "python script.py";
process.start(exe);
process.waitForFinished(-1);
QString output(process.readAllStandardOutput());
qDebug() << output << endl;
还有我的 script.py
import sys
print("Hello world!")
奇怪的是,当我将“python script.py”更改为“ping google.com”时,它的工作就像一个魅力。我也在我的cmd上检查了它,但似乎我的Python安装也不错。 我在哪里做错了?
[编辑 1] 回显%PATH%
C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Users\Micha\AppData\Local\Programs\Python\Python35-32\Scripts\;C:\Users\Micha\AppData\Local\Programs\Python\Python35-32\;C:\NVPACK\gradle-2.9\bin;C:\NVPACK\apache-ant-1.8.2\bin;C:\NVPACK\jdk1.8.0_77\bin;C:\NVPACK\android-ndk-r12b;C:\NVPACK\android-sdk-windows\extras\android\support;C:\NVPACK\android-sdk-windows\build-tools;C:\NVPACK\android-sdk-windows\platform-tools;C:\NVPACK\android-sdk-windows\tools;C:\Users\Micha?\AppData\Local\atom\bin;C:\Users\Micha\AppData\Roaming\npm;C:\Program Files (x86)\Microsoft VS Code\bin
【问题讨论】:
-
你不是说 QString output = process.readAllStandardOutput(); ?
-
它也不能正常工作:(我得到如下输出“”
-
你在linux上吗?
python也可以是python2,试试python3吧。 -
我在 Windows 8.1 上。我将 QtCreator 与 msvc2013 64bit 一起使用
-
因此,请改用
C:\Program Files\Python\python.exe。
标签: python c++ qt output qprocess