0

I want to run script written in Python and get all output from that. This is my cpp code

QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
QString exe = "python script.py";
process.start(exe);
process.waitForFinished(-1);
QString output(process.readAllStandardOutput());

qDebug() << output << endl;

and my script.py

import sys
print("Hello world!")

The strange thing is when I change "python script.py" to "ping google.com" it's working like a charm. I checked it also on my cmd, but it seems that my Python installation is also good. Where I'm doing it wrong?

[EDIT 1] echo %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 
Tatarinho
  • 754
  • 2
  • 11
  • 31

1 Answers1

0

You need to amend your PATH environment variable.

If you used an official installer and accepted the default install location, python will probably be in e.g. C:/Python27, C:/Python35, etc. So you need to add these paths, and probably also e.g. C:/Python27/Scripts.

See: What are PATH and other environment variables, and how can I set or use them?.

Community
  • 1
  • 1
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • what about if I'm running script with full path to Python? QStringList params; params << "script.py"; QString exe = "C:\Python27\python.exe"; process.start(exe, params); – Tatarinho Nov 17 '16 at 21:37
  • Are you saying you get no output when you use the full path? What is the output of: `qDebug() << process.errorString();`? – ekhumoro Nov 17 '16 at 22:10