PDA

View Full Version : How to Send a command to already running process



Rajvesh
30th January 2017, 18:22
Hello,

I have started a cmd.exe. with some arguments.
After starting of the Qprocess , i want to send another argument to the same process.


QProcess *qProc = new QProcess;
qProc->start("cmd.exe",QStringList()<<"/C"<<"C:\\setenv.bat");


Now how to send one more command after the above command to qProc?

Thanks in advance.

jefftee
31st January 2017, 06:22
Hi, I don't think you can do what you want. When you run cmd.exe with args "/C" and "C:\\setenv.bat", it will execute the command c:\setenv.bat and then exit. You can run another cmd.exe via QProcess, but it will be a new process and won't inherit any of the environmental variables you set in c:\setenv.bat.

You could, however, run a batch file that sets environment variables *and* execute whatever other commands you want in one QProcess invocation.

Rajvesh
21st February 2017, 05:02
Hi Jefftee,

Thanks for your answer. Let me try your solution.