Running external Python 3 script
-
wrote on 5 Sept 2019, 21:22 last edited by
I want to run an external .py script that I made. I have tested the script in VS and it runs fine. When I try to implement it in QT, it will not open. Here is what I have in my .cpp file:
QString path = "C:/../python.exe"; QString command("python"); QStringList params = QStringList() << "C:/../test.py"; QProcess *process = new QProcess(); process->startDetached(command, params, path); process->waitForFinished(); process->close();
I do not get any errors when pressing the button, in fact, I get nothing from the output. Any ideas?
-
I want to run an external .py script that I made. I have tested the script in VS and it runs fine. When I try to implement it in QT, it will not open. Here is what I have in my .cpp file:
QString path = "C:/../python.exe"; QString command("python"); QStringList params = QStringList() << "C:/../test.py"; QProcess *process = new QProcess(); process->startDetached(command, params, path); process->waitForFinished(); process->close();
I do not get any errors when pressing the button, in fact, I get nothing from the output. Any ideas?
wrote on 5 Sept 2019, 21:30 last edited by@saltywaffles
What do you mean by "it will not open."? "I get nothing from the output." what output? Why are you usingQProcess::startDetached()
to run your script? How do you know it does not run? -
Hi,
If you want know know exactly what is going on, you should not call startDetached.
Start your QProcess normally and check the it starts correctly and for errors.
-
Hi,
If you want know know exactly what is going on, you should not call startDetached.
Start your QProcess normally and check the it starts correctly and for errors.
wrote on 5 Sept 2019, 22:02 last edited byHow would that look? I am a little lost figuring out the Qprocess
-
You have an example in the Synchronous Process API part of QProcess's documentation.
You have the error method.
You should also check the communication channels. Read the content of the standard output and standard error to see what is happening.
-
How would that look? I am a little lost figuring out the Qprocess
wrote on 7 Sept 2019, 09:14 last edited by JonB 9 Jul 2019, 09:24@saltywaffles
You will need to look at the links @SGaist has given you and implement. But first things first: have you replacedstartDetached()
bystart()
, does that behave differently for you? Or you might find the static https://doc.qt.io/qt-5/qprocess.html#execute a simpler place to start out from: its return code at least tells you what happened when invoking the process, before you proceed to pick up the output. The problem is you still have not explained what you mean by "I get nothing from the output." Does your script send output to stdout which you see when you run it elsewhere (e.g. a terminal) and you want to capture that out in your Qt program? -
I want to run an external .py script that I made. I have tested the script in VS and it runs fine. When I try to implement it in QT, it will not open. Here is what I have in my .cpp file:
QString path = "C:/../python.exe"; QString command("python"); QStringList params = QStringList() << "C:/../test.py"; QProcess *process = new QProcess(); process->startDetached(command, params, path); process->waitForFinished(); process->close();
I do not get any errors when pressing the button, in fact, I get nothing from the output. Any ideas?
@saltywaffles which Qt version are you using?
1/7