Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess start, correct way to pass arguments with > piping to an output file.
Forum Updated to NodeBB v4.3 + New Features

QProcess start, correct way to pass arguments with > piping to an output file.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jonndoe47
    wrote on 14 Apr 2020, 18:09 last edited by
    #1

    Trying to pipe output of an executable to a file. Code is:

    	QString p = QString::fromStdString(param);
    	QStringList arguments;
    	arguments << p;
    
    	proc->start(path, arguments);
    

    The values of the vars at run time are:

    +		p	-listxml > mame.dat	QString
    +		param	"-listxml > mame.dat"	std::string
    +		path	C:\mame\mame64.exe	QString
    

    Now the weird thing.... The debug output:

    >> Started ok
    "Error: unknown option: -listxml > mame.dat\r\n"
    >>>>> Exit Code: QProcess::NormalExit
    Program ran successfully
    

    Where did the "\r\n" come from ? And how do I actually pass a arg to an exe to tell it to pipe in QProcess? And yes, that command via dos works fine. Can 't use a batch file before you ask because this programme will be put up on github and free to use, including source, so that means the end user won't have a batch file there. Hmmm

    J 1 Reply Last reply 14 Apr 2020, 18:39
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 14 Apr 2020, 18:15 last edited by
      #2

      Piping is a bash feature. So either start a bash shell or read the data from stdout and write it to your second process.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • J jonndoe47
        14 Apr 2020, 18:09

        Trying to pipe output of an executable to a file. Code is:

        	QString p = QString::fromStdString(param);
        	QStringList arguments;
        	arguments << p;
        
        	proc->start(path, arguments);
        

        The values of the vars at run time are:

        +		p	-listxml > mame.dat	QString
        +		param	"-listxml > mame.dat"	std::string
        +		path	C:\mame\mame64.exe	QString
        

        Now the weird thing.... The debug output:

        >> Started ok
        "Error: unknown option: -listxml > mame.dat\r\n"
        >>>>> Exit Code: QProcess::NormalExit
        Program ran successfully
        

        Where did the "\r\n" come from ? And how do I actually pass a arg to an exe to tell it to pipe in QProcess? And yes, that command via dos works fine. Can 't use a batch file before you ask because this programme will be put up on github and free to use, including source, so that means the end user won't have a batch file there. Hmmm

        J Offline
        J Offline
        JonB
        wrote on 14 Apr 2020, 18:39 last edited by JonB
        #3

        @jonndoe47
        As @Christian-Ehrlicher says, except that I doubt you'll have bash as you have a .exe so are probably under Windows :) It always helps to state OS when asking QProcess questions....

        The shortest, dirtiest answer is you need to go

        process->start("cmd", QStringList() << "/c" << "C:\\mame\\mame64.exe -listxml > mame.dat")
        

        Nicer here would be to use QProcess::setStandardOutputFile on mame.dat which you have previously opened for output as a QFile yourself in caller. Then you can go back to running "C:\\mame\\mame64.exe" as the executable (and pass -listxml argument). But that's more lines of code (only a couple, you can do that can't you?).

        1 Reply Last reply
        1
        • J Offline
          J Offline
          jonndoe47
          wrote on 14 Apr 2020, 19:25 last edited by
          #4

          Done it all, i forgot > is part of command shell not program.... Doh! All ok now thank you all.

          1 Reply Last reply
          0

          1/4

          14 Apr 2020, 18:09

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved