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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -