PDA

View Full Version : QProcess::execute() outputs in Qt Creator's Application Output



hind
28th October 2014, 06:46
Sorry for having a similar thread at Qt Tools but there is no answer so I have to ask here again.

I need to keeping calling ping at windows so I called

QProcess::execute("ping "+QString(IP)+" -n 1 -w 50")
I have to use this because it gives return values directly so I don't have to analyze the output strings.

But this also gives outputs that should appear at consoles, you know what they are. They just appear at Qt Creator's Application Output, where I usually watch qDebug() outputs. My own outputs are flooded by them.

I know I can use debugview to filter unwanted outputs but I also need to close Qt Creator first to avoid it's intercepting, then open it again to continue my work...

Is there a better way to block the unwanted outputs or just filter them at Qt Creator?

Thank you in advance.

anda_skoa
28th October 2014, 08:37
Hmm, two options:

1) use a script that runs ping and diverts all ping output so that the script has none
2) use a QProcess instance and read&discard the output.

Cheers,
_

wysota
28th October 2014, 08:57
You can't eat the cake and still have the cake. If you can't write three lines of code to intercept standard output from a child process then it will be putting its output into its parent output. You can filter it out by replacing the run command for your program with a script that will run your real application and filter is output but I think it is more work than adding those extra lines of code to your program.

hind
28th October 2014, 09:29
You can't eat the cake and still have the cake. If you can't write three lines of code to intercept standard output from a child process then it will be putting its output into its parent output. You can filter it out by replacing the run command for your program with a script that will run your real application and filter is output but I think it is more work than adding those extra lines of code to your program.
Yes, I do have a way to start the process and receive the output by using other functions of QProcessor. But then I will have to analyze the output myself. As the command "ping" has complex output strings and the program would run on systems of different languages, I need to find a easier way to get the result, and that is why I don't use scripts. The STATIC function QProcess::execute() has a return value, which avoids analyzing result of ping, but I seem losing control of the output at the same time. If there's a way to control the behaviour of the static function I would like to know.

wysota
28th October 2014, 10:05
Yes, I do have a way to start the process and receive the output by using other functions of QProcessor. But then I will have to analyze the output myself. As the command "ping" has complex output strings and the program would run on systems of different languages, I need to find a easier way to get the result, and that is why I don't use scripts. The STATIC function QProcess::execute() has a return value, which avoids analyzing result of ping, but I seem losing control of the output at the same time. If there's a way to control the behaviour of the static function I would like to know.

You don't have to analyze anything.


QProcess process;
process.start("ping", QStringList() << IP << "-n" << "1" << "-w" << "50");
process.waitForFinished();
int exitCode = process.exitCode();