PDA

View Full Version : QProcess -> link output of 3rd party app back to my app



ape
6th March 2008, 13:38
Hi,

at the moment i am using the following construction to launch a 3rd party app from my QT-based UI (developed on and for windows).

The cmd construction looks like this:


QProcess::startDetached("C2oooProgConsole.exe -s -d="+selectedDspType +" -p="+ selectedInterface +" -h="+ windowsFileName +" -c");


So basically the 3rd party app is a commandline based application with some custom parms, which are defined in my UI.

Unfortunaly this output does launch itself in a DOS-Commandbox (cmd.exe) and closes itself after finishing. So i cant even read the output, as the window is already closed again.

As i cant find a parameter for this 3rd party app to let it pause after having finished i was thinking about linking the output directly into my app bck again, so that every single line which happens on the cmd-window is returned to my application UI. In best case i would just link it back to a QTextEdit which i am using right now as log-text-field.

That is the theoretical description....but is that somehow possible ? and if yes what should i search for in the AT doc's ? any suggestion / ideas ?

Best regards
ape

jpn
6th March 2008, 13:50
Try

cmd.exe /k <command> <params..>
Oh, and I believe you should use a QStringList for the arguments, see QProcess::startDetached() docs.

ape
6th March 2008, 14:02
Hi jpn,

my basic construction works but yeah i have realized the QStringList point yesterday already.
Was just wondering if i really need to change my construction...as it was working ok already.

Regarding the pausing option:
your cmd.exe /k idea works great.

Guess i have to add a case-selection for old -windows systems where cmd was called command....but that should be easy right now.

Like always: big thanks to you JPN...you are a big help.
Best regards
ape

ape
12th March 2008, 13:27
Just realized that this construction does have a major problem.

QProcess construction:


QProcess::startDetached("cmd.exe /k C2oooProgConsole.exe -s -d="+selectedDspType +" -p="+ selectedInterface +" -h="+ windowsFileName +" -c");


Problem:
If the variable "windowsFileName" does contains Spaces my QProcess construction does not work.

small example:
a) windowsFileName
C:\testfolder\subfolder\myfile.xy
does work

b) if windowsFileName =
C:\test folder\subfolder\myfile.xy
does NOT work and ends up ion the following error in cmd.exe:

File not found: C:\test

I guess thats the issue cause cmd just cuts the command/path of my file at the moment it reaches the Space. So am i correct, that i need to change my QProcess-construction or better the windowsfileName section to be sure that spaces does not matter anymore ?

But how would i do that ?
Usualy you would just add "" around the path but what is the solution in the contruction above ?

The only theoretical idea i have right now is adding " infront and behind the variable before evne using it. i.e. using prepend and append, but that does not work and i am not sure what is the best method to modify strings AND if this idea is solved better with another method

jpn
12th March 2008, 13:30
You should pass all the arguments in a QStringList.

ape
12th March 2008, 13:45
Hi jpn,

ok i guess this time i really should follow your hint.

I got it working in the meantime using this construction:



windowsFileName.prepend('"');
windowsFileName.append('"');


but thats pretty dirty style.


Gonna test this a bit more and then try to implement your idea.

Like always: big thanks for your fast & good help.

jpn
12th March 2008, 13:53
In fact, it would have been enough to actually read QProcess::startDetached() docs:

On Windows, arguments that contain spaces are wrapped in quotes.



QStringList arguments;
arguments << "/k" << "C2oooProgConsole.exe" << "-s" << ...;
QProcess::startDetached("cmd.exe", arguments);

jsmith
8th May 2009, 11:26
it is popup output along with cmd prompt. how to disappear that cmd prompt