Results 1 to 2 of 2

Thread: qprocess and shell

  1. #1
    Join Date
    Aug 2008
    Location
    Porto Alegre
    Posts
    65
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default qprocess and shell

    I would like to execute a shell command using qprocess, but I would like to pass diferent arguments:
    Qt Code:
    1. QString prog = "/bin/bash";
    2. QStringList arguments;
    3. arguments << "-c" << "gksudo -- mount -o loop /media/100GB/test.iso /media/iso";
    4. QProcess* process = new QProcess(this);
    5. process->start(prog , arguments);
    6. process->waitForFinished();
    7. QString tmp = process->readAll();
    8. qDebug() << tmp;
    9. ui.textEdit->append( "Path to file: " + ui.label_dir->text() + ui.label_file->text() );
    10. ui.textEdit->append(tmp);
    To copy to clipboard, switch view to plain text mode 

    like these:

    Qt Code:
    1. arguments << "-c" << "gksudo -- mount -o loop" << "/media/100GB/test.iso" << "/media/iso";
    To copy to clipboard, switch view to plain text mode 

    How can I do that?

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qprocess and shell

    well, when u run a command using QProcess, u pass the whole command as one argument ONLY.. so the right way to do it as u have done here:

    Qt Code:
    1. arguments << "-c" << "gksudo -- mount -o loop /media/100GB/test.iso /media/iso";
    To copy to clipboard, switch view to plain text mode 

    so if u wanna pass different arguments, at the end of the day u have add them to the command as ONE string

Similar Threads

  1. QProcess & linux shell characters
    By Ti_Thom in forum Qt Programming
    Replies: 4
    Last Post: 21st December 2009, 10:01
  2. Sending Mail through QProcess
    By KaptainKarl in forum Qt Programming
    Replies: 6
    Last Post: 13th August 2008, 21:51
  3. Detect First QProcess finished in a group and kill other
    By Davidaino in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 12:53
  4. Questions about kill() and start() of QProcess
    By mp33919 in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2007, 13:00
  5. Quoting problem with QProcess
    By the_bis in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2006, 11:24

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.