Results 1 to 8 of 8

Thread: QProcess issue in executing a exe with command line 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

    Smile QProcess issue in executing a exe with command line arguments

    Hi,

    I have a issue in setting the QProcess to run executable with the arguments. The Qt code for the same is as below,

    Qt Code:
    1. QProcess* processSQLDB = new QProcess(this);
    2.  
    3. // some path where i require the output
    4. processSQLDB->setWorkingDirectory(sToolAccessfilepath);
    5.  
    6. QString sExeName = "\"D:/app 1/app.exe\"";
    7.  
    8. sArgs << "DBFile.db";
    9. sArgs << "<";
    10. sArgs << sDataFileName;
    11.  
    12. processSQLDB->start( sExeName , sArgs);
    13.  
    14. if (!processSQLDB->waitForStarted())
    15. return false;
    16.  
    17. // to display stdout, stderr,this gives an empty string
    18. qDebug() << processSQLDB->readAll();
    To copy to clipboard, switch view to plain text mode 

    The output of this snippet is the creation of the file "DBFile.db". But it is not happening. Am i doing any mistake?

    But if i goto cmd prompt and execute the same thing like.,

    c:/> "D:/app 1/app.exe" DBFile.db < sDataFileName. This works perfectly.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess issue in executing a exe with command line arguments

    you need to use escape character for the slashes.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    Default Re: QProcess issue in executing a exe with command line arguments

    Even after putting escape character it is not working. And the other thing what i observed is

    1) The exe(exe without args)invokes only if i use startDetached(...) method but not start(...).
    2) Even if the exe do not contains path and i try to execute the QProcess() plainly having all the required files in the current directory then also am not able to get the output. But if use something like this ,

    Qt Code:
    1. QString str = "app.exe" + " DBFile.db" + " < " + sDataFileName;
    2.  
    3. system(str.toAscii());
    To copy to clipboard, switch view to plain text mode 

    This works!!,But the problem is, this flashes the cmd window, which is not appreciated. Any inputs would be helpful. Thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess issue in executing a exe with command line arguments

    even after putting escape character it is not working. And the other thing what i observed is
    Please post the code
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess issue in executing a exe with command line arguments

    did you use waitForFinished() before taking out the std output

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

    Default Re: QProcess issue in executing a exe with command line arguments

    Quote Originally Posted by MrDeath View Post
    did you use waitForFinished() before taking out the std output
    yes. I tried that too. But there won't anything directed stdout, the confirmation is creation of the DBfile.db. And also there is no any stderror data too. Let me know if anything need to do.

    Quote Originally Posted by high_flyer View Post
    Please post the code
    I have used the same code posted above with small changes as suggested below,

    First way:
    Qt Code:
    1. QString sExeName = "\"D:\\app 1\\app.exe\"";
    To copy to clipboard, switch view to plain text mode 
    Second way:
    Qt Code:
    1. QString sExeName = "\"D:/app 1/app.exe\"";
    To copy to clipboard, switch view to plain text mode 

    And also as said in the above post, even i dump all the files in the current directory then also there is no output, means creation of file but whick works with the 'Sytem(...) command.
    Last edited by nikhilqt; 12th November 2010 at 11:24.

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

    Default Re: QProcess issue in executing a exe with command line arguments

    Guys, Please let me know if you have any inputs?

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess issue in executing a exe with command line arguments

    try this:
    Qt Code:
    1. QString sExeName = "D:\\app 1\\app.exe";
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 1
    Last Post: 7th September 2010, 15:49
  2. Replies: 3
    Last Post: 23rd February 2010, 04:33
  3. Internal Qt4 Standards for Command Line Arguments
    By wswartzendruber in forum Newbie
    Replies: 3
    Last Post: 8th October 2009, 07:16
  4. QTest and Command Line Arguments
    By ManuMies in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2009, 12:32
  5. Retrieving command line arguments inside a Qt application
    By prykHetQuo in forum Qt Programming
    Replies: 5
    Last Post: 14th February 2009, 14:28

Tags for this Thread

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.