Results 1 to 5 of 5

Thread: how to execute multiple commands at a time

  1. #1
    Join Date
    Aug 2011
    Location
    bangalore
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default how to execute multiple commands at a time

    hi, i want to execute mutiple commands at a time when i click button. this slot is not working properly when i commented to the second write it is working fine.please some one clarify my doubt. is it possible to execute multiple commands one by one?if possible how to do it?

    Qt Code:
    1. process = new QProcess(this);
    2. process->start ("sh");
    3. process->waitForStarted();
    4. process->write("vi sample.txt\n");
    5. process->write("vi text.text\n");
    6. process->closeWriteChannel();
    7. process->waitForFinished();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2006
    Location
    indonesia
    Posts
    55
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to execute multiple commands at a time

    Hi,
    I think this is a duplicate question.

    Please check this link : http://toto-share.com/2011/11/qt-qprocess-in-a-loop/
    I think you will get an idea how to solve your problem.
    Thank you.

    Best regards,

    myta

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to execute multiple commands at a time

    I think you're doing it wrong. you can't simply open two vi's in a row (in a single terminal).
    open a terminal and write what you're writing to the process and you'll see it doesn't work.
    In your case you have to exit first vi to open another or open another shell (process).
    in other cases you can use ";" as a separator of commands, ie "cd /home/my_user/;ls;touch test.file;".

  4. #4
    Join Date
    Aug 2011
    Location
    bangalore
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to execute multiple commands at a time

    Thanks for replying ."Spitfire" your suggestion is correct we cannot open two vi's at a time if i closed first one next vi window is opening.i got one more problem
    Qt Code:
    1. void MainWindow::on_pushbuttonclicked()
    2. {
    3. process3->setWorkingDirectory ("/hdrd/iimd/");
    4. process3->start ("gnuplot");
    5. process3->waitForStarted();
    6. process3->write( "set pm3d\n" );
    7. process3->write( "splot \"plot.dat\" u 1:2:3 with line &\n" );
    8. process3->waitForFinished();
    9. //process3->closeWriteChannel();
    10. }
    To copy to clipboard, switch view to plain text mode 

    This is my code actually this code will open some other window which is having gnuplot(graph).with out "process->closewritechannel()" i am getting ouput properly but when clicked the pushbutton again it showing some warning like this "QProcess is already running".i tried with adding "process->closewritechannel()" statement output window is just appearing one or two seconds and closeing ...give some idea how to make that output window stable and terminate the process

  5. #5
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to execute multiple commands at a time

    You can't do it well in a single method because you'll freeze the UI.

    waitForFinished() is a blocking call and will make your app unresponsive.
    Instead, you should use finished() signal from QProcess and connect it to a slot which will terminate the process.

    As to the other issue, it should be obvious why you get the message - it's because you never exit the process and try to run it again (unless you do it in other place which you didn't show).
    Qt Code:
    1. void MainWindow::MainWindow()
    2. {
    3. connect( process3, SIGNAL( finished() ), this, SLOT( process3FinishedSlot() ) );
    4. }
    5.  
    6. void MainWindow::on_pushbuttonclicked()
    7. {
    8. process3->setWorkingDirectory ("/hdrd/iimd/");
    9. process3->start ("gnuplot");
    10. process3->waitForStarted(); // blocking call, consider using started() signal if it takes long to start the process
    11. process3->write( "set pm3d\n" );
    12. process3->write( "splot \"plot.dat\" u 1:2:3 with line &\n" );
    13. }
    14.  
    15. void MainWindow::process3FinishedSlot( void )
    16. {
    17. process3->close();
    18. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 7
    Last Post: 13th September 2011, 13:15
  2. Calling Multiple Exes at the same time
    By chandru@080 in forum Newbie
    Replies: 7
    Last Post: 16th December 2010, 22:15
  3. Replies: 2
    Last Post: 5th October 2010, 08:20
  4. Execute an action on regular time
    By valy12 in forum Qt Programming
    Replies: 2
    Last Post: 21st May 2010, 10:25
  5. add multiple rows at a time in tablewidgets
    By rk0747 in forum Qt Programming
    Replies: 0
    Last Post: 15th April 2010, 06:54

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.