c++ - How to execute a cmd command using QProcess? -
i attempting execute cmd command using
qprocess::startdetached("cmd /c net stop \"myservice\"");
this not seem stop service. however, if run start >> run, works.
qprocess::startdetached take first parameter command execute , following parameters, delimited space, interpreted separate arguments command.
therefore, in case: -
qprocess::startdetached("cmd /c net stop \"myservice\"");
the function sees cmd command , passes /c, net, stop , "myservice" arguments cmd. however, other /c, others parsed separately , not valid arguments.
what need use quotes around "net stop \"myservice\" pass single argument, give you: -
qprocess::startdetached("cmd /c \"net stop \"myservice\"\"");
alternatively, using string list use: -
qprocess::startdetached("cmd", qstringlist() << "/c" << "net stop \"myservice\"");
Comments
Post a Comment