Results 1 to 3 of 3

Thread: Qt4/C++ - QProcess - bin/bash script that expects input

  1. #1
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Qt4/C++ - QProcess - bin/bash script that expects input

    Hello,

    Qt4 / Linux

    I'm using QProcess to start a script (myScript.sh) that expects a response.
    At the moment I divert the output from the script to a QTextBox.
    I never get the yes/no question.
    There is more output from the script after the question.
    Is it possible to get the question to display? Answer it and get the rest of the output.
    I don't want to modify the script.

    Regards

    Qt Code:
    1. QObject::connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput()));
    2. QObject::connect(process, SIGNAL(readyReadStandardError()), this, SLOT(processOutput()));
    3. process->start(myCommmands);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void myProg::processOutput()
    2. {
    3. myOutput = new ee_output("Script output", this);
    4.  
    5. myOutput->t1->setText("Standard output:\n");
    6. myOutput->t1->append(process->readAllStandardOutput());
    7. myOutput->t1->append("Standard Error:\n");
    8. myOutput->t1->append(process->readAllStandardError());
    9. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. This is the textbox display:
    2. Standard output:
    3.  
    4. This script comes with ABSOLUTELY no warranty. Continue only if you know what you are doing.
    5.  
    6. Standard Error:
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. This is the terminal output:
    2. ...$ sudo ./myScript.sh -w -f=/home/pi/myFiles/test9999.eep -t=24c256
    3. This script comes with ABSOLUTELY no warranty. Continue only if you know what you are doing.
    4. Do you wish to continue? (yes/no): _
    To copy to clipboard, switch view to plain text mode 
    Last edited by jimbo; 23rd May 2015 at 13:53.

  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: Qt4/C++ - QProcess - bin/bash script that expects input

    If you do not get the question the program might not write it to its standard out/err but to the controlling terminal instead.

    To check, run the command manually but divert its outputs to files. If the question still appears it is being written to the terminal

    Qt Code:
    1. program > stdout.txt 2> stderr.txt
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    jimbo (26th May 2015)

  4. #3
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt4/C++ - QProcess - bin/bash script that expects input

    Hello,

    Thanks for your reply.

    I tried you suggestion and got:
    Qt Code:
    1. cat stdout.txt
    2. This script comes with ABSOLUTELY no warranty. Continue only if you know what you are doing.
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. cat stderr.txt
    2. Do you wish to continue? (yes/no):
    To copy to clipboard, switch view to plain text mode 
    OK its being written to one of the files, doesn't show in the textBox.

    Regards
    Last edited by jimbo; 23rd May 2015 at 19:07.

Similar Threads

  1. Replies: 1
    Last Post: 18th November 2014, 18:18
  2. Running a bash script from resource (qrc) file
    By onamatic in forum Qt Programming
    Replies: 4
    Last Post: 3rd February 2012, 10:09
  3. Running an script using QProcess
    By DiegoTc in forum Newbie
    Replies: 1
    Last Post: 31st December 2010, 18:02
  4. QProcess + Bash
    By bunjee in forum Qt Programming
    Replies: 4
    Last Post: 25th August 2009, 11:56
  5. QProcess Bash in Event Filter (Multiple Processes)
    By Arsenic in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2008, 08:42

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.