Results 1 to 8 of 8

Thread: QProcess and stdin

  1. #1
    Join Date
    Mar 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QProcess and stdin

    Hi, i have a simple program like this:
    Qt Code:
    1. int main()
    2. {
    3. int a;
    4. printf("something\n");
    5. scanf("%d",&a);
    6. }
    To copy to clipboard, switch view to plain text mode 

    and i'm running this program with QProcess but QProcess dont want to emit readyReadStandartOutput() signal until i use write().
    It is possible to read data from stdout before i write something to process's stdin? and i dont mean closeWriteChannel() coz i need to write some data later after i read from stdout.

    sry for my bad english,
    regards
    ithinkso

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QProcess and stdin

    Probably the output is buffered, and you'll need to flush the buffer yourself.
    Try this:
    Qt Code:
    1. printf("something\n");
    2. fflush(stdout);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess and stdin

    I can't integrate in this little cpp source code, I need to do something like console in simple c++ IDE, compiling, running works fine but its not interactive due to this problem with stdout buffer :/
    It is possible to flush process stdout buffer from another process?

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess and stdin

    Not that I'm aware of, Have you tried just sending something like "\n" ?

  5. #5
    Join Date
    Mar 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess and stdin

    It's "cheating" i think, i mean how do IDE program based on Qt works? They send '\n' to process?

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

    Default Re: QProcess and stdin

    Quote Originally Posted by ithinkso View Post
    It is possible to flush process stdout buffer from another process?
    You can request QProcess to create the stdin/stdout descriptors in unbuffered 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.


  7. #7
    Join Date
    Mar 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess and stdin

    Quote Originally Posted by wysota View Post
    You can request QProcess to create the stdin/stdout descriptors in unbuffered mode.
    start() process with QIODevice::Unbuffered makes no changes, u mean other solution?

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

    Default Re: QProcess and stdin

    Quote Originally Posted by ithinkso View Post
    start() process with QIODevice::Unbuffered makes no changes
    Then it is not buffering that is to blame.
    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.


Similar Threads

  1. Replies: 0
    Last Post: 26th August 2010, 10:44
  2. Replies: 0
    Last Post: 2nd August 2010, 09:17
  3. Replies: 8
    Last Post: 26th March 2010, 12:45
  4. Looking to NOT echo input when writing to stdin
    By ultim8 in forum Qt Programming
    Replies: 1
    Last Post: 19th June 2009, 21:57
  5. IPC / reading stdin within non-GUI thread
    By mule in forum Qt Programming
    Replies: 3
    Last Post: 29th November 2007, 22:11

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
  •  
Qt is a trademark of The Qt Company.