PDA

View Full Version : QProcess running batch file



Vit Stepanek
15th June 2010, 15:49
Hi,
I execute a batch file from my application using QProcess. The batch file consists of 2 comands, first calls another batch file, which sets a lot of necessary vars, second calls the executable. This executable needs those previously defined variables, otherwise it won't work.
All's fine up to now. Process works, output is being catched. But the problem comes when I terminate the process. Apparently the execution of batch file is stopped and the QProcess object terminates correctly. However the executable called from the batch file continues in execution.

Since this could be more a batch file problem, I tried to run the batch file (that one setting path variables) from the separate QProcess and wanted to read the variables using QProcess::environment; but this always returns the empty list. If this would work, problem is solved (I'd avoid calling batch file and call the executable directly from a QProcess).
Then I searched for some way how to see running processes and through this to find child processes of a process running a batch file. Without success.

Does anybody has an idea? Perhaps another solution? Thanks for everything.

Vit

Here's a batch file (template without resolved parameters):


call "%BLDTOOLS%vars.bat"
call bldexe __mode__ "__proj__" "__config__"

Vit Stepanek
22nd June 2010, 15:23
For those who'd be interested in the solution, here's how I solved the problem.
As I've found, QProcess::terminate does nothing except putting the process to sleep (console app here). After timeout the execution continues. When QProcess::kill is used, the process terminates immediately but leaves all it's child processes running.
Since I'm on WinXP only, I created small function calling win api, which loops through all running processes, reads their parent process ids and closes my process' child processes. I was inspired by a great article from CodeProject: http://www.codeproject.com/KB/threads/ParentPID.aspx.

However I'm still a bit confused that Qt doesn't provide anything for process handling. And I don't believe nobody ever needed that.

See the attached file with mentioned functions.

Vit