Results 1 to 4 of 4

Thread: Issue with QProcess and redirectiion operator as arguments

  1. #1
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Wink Issue with QProcess and redirectiion operator as arguments

    Hi,

    I am using QProcess for executing an executable and the syntax goes like this,

    QString cmd = " some.exe"
    QStringList args;

    args << " < " << "./input.txt" << " > " << "./output.txt"

    QProcess* proc = new QProcess( this );

    proc.start( cmd , args );
    proc.waitForStarted();

    As per the above code the exe has to run taking " args " as argument list. since i have provided the input to "some.exe" using redirection operator it should not ask user the input, but it is not happening as expected.

    but if i provide the same commands in .bat file and if i give that bat file as input for QProcess it works as expected.

    Can anyone throw light on this , why exactly it is not able to run ?

    Thanks in advance,
    Nikhil

  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: Issue with QProcess and redirectiion operator as arguments

    provide args in one string:

    args << " < input.txt > output.txt"

    hopefully it'll work

  3. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Issue with QProcess and redirectiion operator as arguments

    ">" is not an argument to your program, but to the shell executing your program.
    if you call "sh" and pass the rest (including your app) as args, it might work.

    On the other hand, maybe (only maybe) you don't need to redirect the output:
    * if you want to ignore it: just close the channel on the QProcess
    * if you want to read it with Qt: no need to write it to a file first, just read from QProcess

  4. #4
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Issue with QProcess and redirectiion operator as arguments

    Thanks a lot for the reply. I will try them.

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.