我想運行用Python編寫的腳本並獲取所有輸出。 這是我的cpp的代碼從QT中的Python腳本獲取輸出
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!")
奇怪的是當我改變「蟒蛇script.py」到「平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輸出= process.readAllStandardOutput(); ? –
它不工作太:(我得到輸出像下面 「」 – Tatarinho
你在Linux上?'python'也可以'python2',嘗試'python3'來代替 –