Results 1 to 2 of 2

Thread: QProcess running batch file

  1. #1
    Join Date
    Apr 2010
    Posts
    34
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QProcess running batch file

    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):

    Qt Code:
    1. call "%BLDTOOLS%vars.bat"
    2. call bldexe __mode__ "__proj__" "__config__"
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2010
    Posts
    34
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess running batch file

    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
    Attached Files Attached Files

  3. The following user says thank you to Vit Stepanek for this useful post:

    Fenix Voltres (27th April 2011)

Similar Threads

  1. Replies: 7
    Last Post: 14th June 2010, 02:42
  2. Replies: 5
    Last Post: 17th March 2010, 18:30
  3. distclean batch file
    By talk2amulya in forum Qt Programming
    Replies: 0
    Last Post: 11th April 2009, 12:19
  4. Connecting with QProcess to an already running process
    By high_flyer in forum Qt Programming
    Replies: 7
    Last Post: 26th November 2007, 10:31
  5. QProcess problem with windows batch file
    By bood in forum Qt Programming
    Replies: 11
    Last Post: 6th January 2006, 08:08

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.