QProcess ReadAll Output from EXE
-
Hello guys,
So I have these lines of C++:
QProcess qp1; qp1.start("C:\\Users\\ariie\\Desktop\\moboTemp.bat"); qp1.waitForFinished(); qDebug() << "qp1:" << qp1.readAll();
That works perfectly; it runs a WMIC command to get my Motherboard temperature, and displays its' standard output.
The output in this case is "qp1: "29.85 Degrees Celsius\r\n"".However, now I want to replace the bat file with an exe. In particular, I'm trying to access a NVIDIA EXE that collects GPU information such as temperature, load, etc..
First of all, the file path location is "C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe", which brings me to my first question. NVIDIA -SPACE- Corporation and Program -SPACE- Files. Is this OK? I know that some environments can't deal with spaces, and it isn't really possible to change the location of NVSMI without reinstalling my GPU drivers.
Secondly, how do I add command-line parameters to that EXE via QProcess? Do I just add them on the end of the EXE like regular parameters, or do I have to add more arguments to QProcess.start?
Here is the full command-line string I'm trying to get output from:
"C:\\Program Files\\NVIDIA Corporation\\NVSMI\\nvidia-smi.exe" --query-gpu=clocks.gr,fan.speed,power.draw,temperature.gpu,utilization.gpu --format=csv,noheader
Which displays the following output in cmd:
1177 MHz, 31 %, 72.56 W, 55, 34 %
But in Qt, when I use the following:
qp1.start("'C:\\Program Files\\NVIDIA Corporation\\NVSMI\\nvidia-smi.exe' --query-gpu=clocks.gr,fan.speed,power.draw,temperature.gpu,utilization.gpu --format=csv,noheader"); qp1.waitForFinished(); qDebug() << "qp1:" << qp1.readAll();
I simply get "" as a result. I'm fairly certain it's something to do with the syntax; either I have to do some wizardry to eliminate the space in the file path, or I'm not using QProcess correctly.
Does anyone have any hints? Any help is greatly appreciated.
Thanks,
Ryan -
Hi,
Did you try using escaped double quotes for your path rather than single quotes ?
-
Pass the parameter separately with setArguments()
-
As usual, @SGaist, you're right!
Solution is:
QProcess qp1; qp1.start("\"C:\\Program Files\\NVIDIA Corporation\\NVSMI\\nvidia-smi.exe\" --query-gpu=clocks.gr,fan.speed,power.draw,temperature.gpu,utilization.gpu --format=csv,noheader"); qp1.waitForFinished(); qDebug() << "qp1:" << qp1.readAll();
Thanks,
Ryan