Results 1 to 3 of 3

Thread: Passing ">" to Qprocess command line

  1. #1
    Join Date
    Jan 2012
    Location
    Canary Islands, Spain
    Posts
    86
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Passing ">" to Qprocess command line

    I'm trying to pass an argument to an exe file with QProcess in Windows:

    procMame->start( tinfo.absoluteFilePath(), QStringList() << "-listxml" <<">" << "mamelist.xml");
    or
    procMame->start( tinfo.absoluteFilePath(), QStringList() << "-listxml>" <<" "mamelist.xml");
    or
    procMame->start( tinfo.absoluteFilePath(), QStringList() << "-listxml" << ">mamelist.xml");
    or
    procMame->start( tinfo.absoluteFilePath(), QStringList() << "-listxml>mamelist.xml");
    or
    procMame->start( tinfo.absoluteFilePath(), QStringList() << "-listxml > mamelist.xml");

    Nothing works, but it does work manuall via CMD console...
    With QProcess the command is never recognized (Command not found or takes ">" as a game name not as a output character for saving the xml file).
    What i'm doing wrong?
    Always trying to learn >.<

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Passing ">" to Qprocess command line

    When you type the command
    Qt Code:
    1. foo.exe arg > bar
    To copy to clipboard, switch view to plain text mode 
    in the terminal, then the command interpreter (CMD) does NOT run foo.exe with the argument list {"arg", ">", "bar"}, because ">" is a part of the special syntax interpreted by CMD. Instead, CMD runs foo.exe with the single argument "arg" and writes its output to the file bar.

    Therefore, you can either:
    • (Recommended) Do like CMD: with a QProcess, run foo.exe with the single argument "arg", and use QProcess::setStandardOutputFile() to redirect the output to a file.
    • Run CMD itself, so that it interprets the command: with a QProcess, run cmd.exe with the appropriate argument list, starting with "/c", and following with an escaped version of the command (which is tricky to get right). This is roughly equivalent to calling the system() function from the standard C library.

  3. #3
    Join Date
    Jan 2012
    Location
    Canary Islands, Spain
    Posts
    86
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Passing ">" to Qprocess command line

    Thanks!! The Option 1 (redirect output to a file) is perfect.
    Sometimes the answer is out there..
    Thanks again
    Always trying to learn >.<

Similar Threads

  1. Replies: 3
    Last Post: 16th March 2015, 07:31
  2. Replies: 1
    Last Post: 3rd December 2013, 02:19
  3. Replies: 7
    Last Post: 20th October 2012, 13:44
  4. How to run "more" command using Qprocess ???
    By jesse_mark in forum Qt Programming
    Replies: 9
    Last Post: 4th October 2012, 19:52
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

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.