Results 1 to 6 of 6

Thread: running a cmd command using Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,348
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: running a cmd command using Qt

    How many times does this same question have to be answered in this forum?

    If you want to run a command with command line parameters using QProcess, you have to give QProcess::start() or QProcess::startDetached() at least two arguments: a QString containing the command to be executed and a QStringList containing the parameters to the command:

    Qt Code:
    1. QString command( "cmd.exe" );
    2. QStringList params = QStringList() << "/k" << "ping" << "1.1.1.1" << "-n" << ... and so forth
    3.  
    4. QProcess::startDetached( command, params );
    To copy to clipboard, switch view to plain text mode 

    QProcess::startDetached() is a static method, therefore no QProcess instance is required.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. The following user says thank you to d_stranz for this useful post:

    anda_skoa (3rd March 2017)

  3. #2
    Join Date
    Aug 2017
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    1

    Default Re: running a cmd command using Qt

    Quote Originally Posted by d_stranz View Post
    How many times does this same question have to be answered in this forum?

    If you want to run a command with command line parameters using QProcess, you have to give QProcess::start() or QProcess::startDetached() at least two arguments: a QString containing the command to be executed and a QStringList containing the parameters to the command:

    Qt Code:
    1. QString command( "cmd.exe" );
    2. QStringList params = QStringList() << "/k" << "ping" << "1.1.1.1" << "-n" << ... and so forth
    3.  
    4. QProcess::startDetached( command, params );
    To copy to clipboard, switch view to plain text mode 

    QProcess::startDetached() is a static method, therefore no QProcess instance is required.
    Hi. I took your code above and used in my program but the actual CMD window does not get displayed... I can see in task manager that it was started. How do you get it to display? Apologies for such a noob question, this is my first week into this program... Which is awesome!

    teak
    A little bit of nonsense now and then is cherished by the wisest men...
    - Willy Wonka

Similar Threads

  1. How to Send a command to already running process
    By Rajvesh in forum Qt Programming
    Replies: 2
    Last Post: 21st February 2017, 06:02
  2. read output of command running though ssh
    By Cbr89 in forum Qt Programming
    Replies: 1
    Last Post: 31st January 2017, 08:06
  3. Replies: 2
    Last Post: 7th April 2015, 09:18
  4. Replies: 2
    Last Post: 28th May 2010, 10:16
  5. running shell command from C++ code problem
    By alex chpenst in forum Qt Programming
    Replies: 4
    Last Post: 31st July 2008, 11:41

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
  •  
Qt is a trademark of The Qt Company.