Results 1 to 5 of 5

Thread: QProcess::execute() outputs in Qt Creator's Application Output

  1. #1
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Question QProcess::execute() outputs in Qt Creator's Application Output

    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
    Qt Code:
    1. QProcess::execute("ping "+QString(IP)+" -n 1 -w 50")
    To copy to clipboard, switch view to plain text mode 
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QProcess::execute() outputs in Qt Creator's Application Output

    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,
    _

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess::execute() outputs in Qt Creator's Application Output

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess::execute() outputs in Qt Creator's Application Output

    Quote Originally Posted by wysota View Post
    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess::execute() outputs in Qt Creator's Application Output

    Quote Originally Posted by hind View Post
    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.

    Qt Code:
    1. QProcess process;
    2. process.start("ping", QStringList() << IP << "-n" << "1" << "-w" << "50");
    3. process.waitForFinished();
    4. int exitCode = process.exitCode();
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    hind (29th October 2014)

Similar Threads

  1. Replies: 0
    Last Post: 23rd September 2014, 03:17
  2. QProcess, problem getting interactive outputs
    By enricong in forum Qt Programming
    Replies: 2
    Last Post: 19th July 2011, 21:20
  3. Replies: 3
    Last Post: 28th February 2010, 08:10
  4. How to use the QProcess to execute the Browser ?
    By eric0214 in forum Qt for Embedded and Mobile
    Replies: 7
    Last Post: 21st December 2009, 10:06
  5. How to use the QProcess to execute the Browser ?
    By eric0214 in forum Qt Programming
    Replies: 2
    Last Post: 17th November 2009, 06:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.