执行cmd命令

1.使用QProcess执行cmd命令

QStringList args;
QString sCmd = QString("net stop mysql_psasp57");
args << "/c" << sCmd;
 
QProcess process;
process.execute("cmd.exe", args);
process.waitForFinished();
process.close();

2.调用ShellExecuteA函数

#include <Windows.h>
QString sCmd = QString("/c net stop mysql_psasp57");
ShellExecuteA(NULL, NULL, "cmd.exe", sCmd.toLocal8Bit().data(), NULL, SW_HIDE);

3.调用system函数,窗口不能隐藏

#include <stdlib.h>
QString sCmd = QString("cmd.exe /c net stop mysql_psasp57");
system(sCmd.toLocal8Bit().data());


版权声明:本文为GraceLand525原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。