Results 1 to 11 of 11

Thread: QProcess and console programs

  1. #1
    Join Date
    Jul 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QProcess and console programs

    Hello )
    When start console program using QProcess's start() function, this program is invisible (no window). Is it possible to start it in window but have control on it by means of QProcess (start/stop, view status etc)?

  2. #2
    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 and console programs

    You'd have to open a terminal program (like xterm) from QProcess and ask it to run the application you wish to control. But it might be easier if you dedicate a text edit widget where you will just display the output of the application.

  3. #3
    Join Date
    Jul 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess and console programs

    Unfortunatelly its not always possible to catch console program output - it is often buffered and not available.
    xterm works, and hope on all *nix platforms, including Mac?
    But do you know similar workaround in windows ?

  4. #4
    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 and console programs

    What do you mean by buffered? If it's buffered, you won't see it in the terminal as well... So using xterm (or not) wouldn't change a thing.

  5. #5
    Join Date
    Jul 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess and console programs

    Quote Originally Posted by wysota View Post
    What do you mean by buffered? If it's buffered, you won't see it in the terminal as well... So using xterm (or not) wouldn't change a thing.
    for example, such code:
    Qt Code:
    1. puts("Some strings..");
    2. gets(s);
    3. puts(s);
    4. ...
    To copy to clipboard, switch view to plain text mode 
    will not output anything to QProcess until console program end
    But if you add
    Qt Code:
    1. setvbuf(stdout,NULL,0,_IOFBF);
    To copy to clipboard, switch view to plain text mode 
    before these strings, it will work.

  6. #6
    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 and console programs

    Have you heard about a function called fflush()?

  7. #7
    Join Date
    Jul 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess and console programs

    Quote Originally Posted by wysota View Post
    Have you heard about a function called fflush()?
    where can i use this function? console programs i told about aren't my and i can't do anything with its code.
    as i understand, QProcess is implemented so that it never show console program window - and i wonder why it isn't an option.. so i need to invent various workarounds. very strange imho.

  8. #8
    Join Date
    Mar 2006
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 3 Posts

    Default Re: QProcess and console programs

    it's your?
    http://prog.org.ru/forum/topic_5677_...ed38e6971.html


    i have try
    Qt Code:
    1. fflush(stdout);
    To copy to clipboard, switch view to plain text mode 
    after puts(s); -- and all work right;
    so problem to call flush in your class -- maybe start timer after myProc.write() with little delay

  9. #9
    Join Date
    Mar 2006
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 3 Posts

    Default Re: QProcess and console programs

    check this
    Qt Code:
    1. QProcess::closeWriteChannel ()
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jul 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess and console programs

    Well, it seems i need to specify some details:
    Suppose i have console program (worked in text mode), without any source - only executable (so i cant change anything in this program, like put fflush() somewhere in it), which periodically outputs some info to the screen (for example, gets it from network), and allows me to input some "commands" which it then "process" and shows me result. To stop this program i need to enter "quit" command.
    I want to start several such programs from one Qt application and have ability to check running status and stop/restart them if necessay. And also it would be very desirable to get access to program console.
    But if i do that with QProcess start() method, i cant get program window, cant view program output and cant input anything (well, may be can - but dont see it).
    If i use startDetached() - i get program window, but lose control at it from my Qt application.
    Any ideas?

    evgenM: closeWriteChannel() works in my simple example (just stop it), but doesnt work in other cases

  11. #11
    Join Date
    Mar 2006
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 3 Posts

    Default Re: QProcess and console programs

    i realy not understand the problem - u do right all u must do - problem only in this bugged console app (no flush) - i am not sure u can fix it in YOUR app. So u have one way - ask author to correct.

Similar Threads

  1. Replies: 8
    Last Post: 28th January 2015, 09:45
  2. How to run a console program "silently"?
    By fullmetalcoder in forum Qt Programming
    Replies: 9
    Last Post: 23rd July 2006, 10:03
  3. QProcess / system call not working under linux. Why?
    By johnny_sparx in forum Qt Programming
    Replies: 12
    Last Post: 11th March 2006, 00:32

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.