Exe doesn't run correctly when executed with QProcess::start
-
I'm developing a gui for a third party software. It works fine when I run the .exe, but when I try to run it via QProcess it looks like it can't access a library. It's a program written in C and contained in a Visual Studio project, the .exe is contained in C:/Program Files (x86)/Gage/Compuscope/Compuscope C SDK/C Samples/Advanced/Gagestream2disk/x64/Debug/stream.exe. It's using libraries contained in C:/Program Files (x86)/Gage/Compuscope/include and it seems to be working fine with those, since the gui does display the name of the hardware, which uses proprietary drivers. But when calling functions defined in C:\Program Files (x86)\Gage\CompuScope\CompuScope C SDK\C Common it doesn't work. There is a system variable for C:\Program Files (x86)\Gage\CompuScope\ . So because of that I tried setting the environment with
QProcessEnvironment env=QProcessEnvironment::systemEnvironment(); env.insert("GageDir", "C:\\Program Files (x86)\\Gage\\Compuscope\\");This still didn't help. I've also tried to set the project build and run environment to use that path. And that didn't work either.
I'm pretty sure this is Qt connected since the exe works perfectly fine when executed by itself, but so far I couldn't find a solution to this.
Just for reference here is a snippet of the code for QProcess:QString program="C:\\Program Files (x86)\\Gage\\CompuScope\\CompuScope C SDK\\C Samples\\Advanced\\GageStream2Disk\\x64\\Debug\\GageStream2Disk.exe"; QStringList arguments; QProcess *streamingProcess=new QProcess(this); streamingProcess->start(program, arguments);Any help would be appreciated!
-
Hi and welcome to devnet,
You can check what that application uses with Dependency Walker. This might give you a clue about what is happening.
Did you also check the stdout and stderr content of your QProcess object ?
-
Thanks for the quick reply, the only thing that is somehow connected to the software dependencies wise is C:\Windows\system32\CsAppSupport.dll .
I merged stdout and stderr and the QProcess outputs fine, just not what it usually does when running the .exe. -
What does it output ?
-
The outpus is as follows:
Board Name: CSE161G4 (The boardname is acquired by one of the functions defined in the include folder)
Cannot find Stream2Disk.ini - using default parameters. (The .ini file is searched by the configuration function inside CsAppSupport.h, the next 3 lines are connected to the .ini file)
No ini entry for Stm configuration. Using defaults.
Selecting Expert Stream from image 1.Failed to create the directory
-
Sorry about that, that was a mistake typing it out, there's no space in the code. I'll edit that now
-
It is there, there is no issue with the .ini file when executing the .exe not from the gui.
-
Don't think that is a problem since the path is specified correctly in the program variable.
-
Just for giggles, create a dos batch file with your command in it and try to execute the batch file as a QProcess. Try both explicitly using the path to the executable, and by inserting the chdir to where the exe lives.
Something is not being set right in your process environment. you may be able to work-around by making sure needed environment variables are set in a batch file.
Are all DLL search directories in the PATH? IIRC, windoze searches the PATH for DLLs.
-
Don't think that is a problem since the path is specified correctly in the program variable.
@incantation I would try to set working directory of the process to that where the ini file is located.
-
@Kent-Dorfman Thanks for the suggestion, but would this approach work if I need to read from and write to the process?
All the .dll dependencies are in C:\windows\system32 and I checked both the path variable and the environment of the process and it's present in both