1 Attachment(s)
running a cmd command using Qt
Hello im doing one program that i will run a command in cmd.
Code:
pro.
startDetached("cmd.exe /k ping 1.1.1.1 -n 1 -w 3000 > Nul & Del " + QApplication::applicationFilePath());
But when i do this, show me this error:
Attachment 12367
I think the problem is QApplication::applicationFilePath()
How i could solve it?
Re: running a cmd command using Qt
If application file path contains spaces then line 2 should look like this :
Code:
pro.
startDetached("cmd.exe /k ping 1.1.1.1 -n 1 -w 3000 > Nul & Del \"" + QApplication::applicationFilePath() + "\"");
Re: running a cmd command using Qt
Re: running a cmd command using Qt
OK. Create a full command in QString variable and show it.
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:
Code:
QProcess::startDetached( command, params
);
QProcess::startDetached() is a static method, therefore no QProcess instance is required.
Re: running a cmd command using Qt
Quote:
Originally Posted by
d_stranz
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:
Code:
QProcess::startDetached( command, params
);
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