ur

kill child process

12 posts in this topic

I have created below code to run the python file.

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=icon.ico
#AutoIt3Wrapper_Outfile=RunTaskRun.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.0
 Author:        Uday Kiran Reddy(ur)

 Script Function:
    To log python data to a file.

#ce ----------------------------------------------------------------------------
#include <MsgBoxConstants.au3>
#include "C:\Automation\ISMBuild\Library.au3"
#include "ProcessEx_AddedNewEntryForLogging.au3"
#include "CheckChangeinCommit.au3"

If not NoChangesRequired() Then
    SendMail("Changes are in commit of erwin-main Repo","Will intimate once binaries are copied to Installshield machine")
    $hProcessHandle = _Process_RunCommand($PROCESS_RUN, $PROCESS_COMMAND & "C:\Python27\python.exe C:\BuildServer\AutoBuildServer\TaskRun.py") ; Capture the Process Handle
    $iPID = @extended ; Note the PID
    $returncode = _Process_DebugLogRunCommand($hProcessHandle, $iPID) ; Display the results in real-time
    Logging("Completed with ReturnCode "&$returncode)
Else
    SendMail("No Changes are not there in commit of erwin-main Repo","So no Binaries for today.If it is needed, please remove the text file from location: "& @TempDir&"\git_erwin_commit.txt")
EndIf

When I kill the autoit execution exe in the middle of execution, it is not terminating the python.exe launched from script.

Can you suggest how to do this?

Share this post


Link to post
Share on other sites



Have a look at OnAutoItExitRegister function in the help file.

Share this post


Link to post
Share on other sites

Define Kill process?

When truly killing the process, one can't expect any cleanup, but when you "instruct" the main process to terminate itself, you could also ensure all cleanup is arranged before terminating itself.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
On 2/4/2017 at 1:34 PM, Subz said:

Have a look at OnAutoItExitRegister function in the help file.

Through this I can wireup a function to execute at the end.

But I can't kill python.exe directly in this function as it might kill other scripts running also instead of the one I invoke.

Anyother approach so that I can kill only the one I launched through my program if I click on the exit at the tray icon of the main script?

Share this post


Link to post
Share on other sites

Can you get PID from your _ProgressRunCommand?  If so you can just kill that PID.

Share this post


Link to post
Share on other sites

_ProgressRunCommand  , I got this file from below UDF 

 

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

After rereading the ProcessEx UDF I realized that it uses CMD to capture the process exit codes etc..  So found an alternative by getting the before and after snapshots of python.exe in the ProcessList this should return the new python.exe as $hPID which allows you to close the process.

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=icon.ico
#AutoIt3Wrapper_Outfile=RunTaskRun.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.0
 Author:        Uday Kiran Reddy(ur)

 Script Function:
    To log python data to a file.

#ce ----------------------------------------------------------------------------
#include <MsgBoxConstants.au3>
#include "C:\Automation\ISMBuild\Library.au3"
#include "ProcessEx_AddedNewEntryForLogging.au3"
#include "CheckChangeinCommit.au3"

If not NoChangesRequired() Then
    SendMail("Changes are in commit of erwin-main Repo","Will intimate once binaries are copied to Installshield machine")
    Local $aProcessList_Before = ProcessList('python.exe')
    $hProcessHandle = _Process_RunCommand($PROCESS_RUN, $PROCESS_COMMAND & "C:\Python27\python.exe C:\BuildServer\AutoBuildServer\TaskRun.py") ; Capture the Process Handle
    Do
        $aProcessList_After = ProcessList('python.exe')
    Until $aProcessList_After[0][0] > $aProcessList_Before[0][0]
    $hPID = Number($aProcessList_After[$aProcessList_After[0][0]][1])
    $returncode = _Process_DebugLogRunCommand($hProcessHandle, $iPID) ; Display the results in real-time
    Logging("Completed with ReturnCode "&$returncode)
Else
    SendMail("No Changes are not there in commit of erwin-main Repo","So no Binaries for today.If it is needed, please remove the text file from location: "& @TempDir&"\git_erwin_commit.txt")
EndIf

 

Edited by Subz
Modified code

Share this post


Link to post
Share on other sites

Please see modification in code above.

Share this post


Link to post
Share on other sites
19 hours ago, Subz said:

After rereading the ProcessEx UDF I realized that it uses CMD to capture the process exit codes etc..  So found an alternative by getting the before and after snapshots of python.exe in the ProcessList this should return the new python.exe as $hPID which allows you to close the process.

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=icon.ico
#AutoIt3Wrapper_Outfile=RunTaskRun.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.0
 Author:        Uday Kiran Reddy(ur)

 Script Function:
    To log python data to a file.

#ce ----------------------------------------------------------------------------
#include <MsgBoxConstants.au3>
#include "C:\Automation\ISMBuild\Library.au3"
#include "ProcessEx_AddedNewEntryForLogging.au3"
#include "CheckChangeinCommit.au3"

If not NoChangesRequired() Then
    SendMail("Changes are in commit of erwin-main Repo","Will intimate once binaries are copied to Installshield machine")
    Local $aProcessList_Before = ProcessList('python.exe')
    $hProcessHandle = _Process_RunCommand($PROCESS_RUN, $PROCESS_COMMAND & "C:\Python27\python.exe C:\BuildServer\AutoBuildServer\TaskRun.py") ; Capture the Process Handle
    Do
        $aProcessList_After = ProcessList('python.exe')
    Until $aProcessList_After[0][0] > $aProcessList_Before[0][0]
    $hPID = Number($aProcessList_After[$aProcessList_After[0][0]][1])
    $returncode = _Process_DebugLogRunCommand($hProcessHandle, $iPID) ; Display the results in real-time
    Logging("Completed with ReturnCode "&$returncode)
Else
    SendMail("No Changes are not there in commit of erwin-main Repo","So no Binaries for today.If it is needed, please remove the text file from location: "& @TempDir&"\git_erwin_commit.txt")
EndIf

THank you very much.

I will try this code and let you know my inputs.

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

On 2/4/2017 at 3:17 AM, Jos said:

Define Kill process?

When truly killing the process, one can't expect any cleanup, but when you "instruct" the main process to terminate itself, you could also ensure all cleanup is arranged before terminating itself.

Jos

I have to ask now, is there a command to "instruct" the process to terminate itself? I've never noticed it but that would be handy indeed.


False Positive Reporter - Mass email all anti virus vendors with an attachment of your program for fast and easy whitelisting.

PortableApps.com App Creation Wizard  - A simple GUI-based Wizard for creating PortableApps.

SoundBoard - Play any song or sound you want at the press of a hotkey.

My GitHub Page: https://github.com/BetaLeaf

Share this post


Link to post
Share on other sites

#11 ·  Posted

13 hours ago, BetaLeaf said:

is there a command to "instruct" the process to terminate itself?

When your script has an GUI, it is easy to send a WinClose message, which then can be handled by the script as the GUI gets closed.
Another option is to monitor for a specific message and act on that.

Jos 

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#12 ·  Posted

Duh. Sorry. I was very tired when writing that stupid question that I already knew the answer to.


False Positive Reporter - Mass email all anti virus vendors with an attachment of your program for fast and easy whitelisting.

PortableApps.com App Creation Wizard  - A simple GUI-based Wizard for creating PortableApps.

SoundBoard - Play any song or sound you want at the press of a hotkey.

My GitHub Page: https://github.com/BetaLeaf

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • Nareshm
      By Nareshm
      If Process exits then end process and ;Some code here {1}
       
      If Process does not exits then ; My {1} Code
    • ur
      By ur
      How to retrieve the target executable path from a process.
      My system is effected with IMG001.exe virus and I remove the folders created by it daily but still it is creating the folders everytime I login to my PC.
      My Antivirus is not detecting it.

       
      So I thought to create a process in AutoIT to check for the process name IMG001.exe and retrieve the process target exe to a log file, so that I can track where it is putting these files.
      With  ProcessExists ( "process" ) , i can get the process ID.
      But how to get the target location of the executable of the process.??
    • salah kai
      By salah kai
      Hey everyone
      i wanna close a process by  path like
      C:\Users\salah\AppData\Local\Temp\a.exe
      processclose(C:\Users\salah\AppData\Local\Temp\a.exe)
      i tried to split the path but i don't know how to know last loop
      and thanks 
       
    • iXX
      By iXX
      Hi!
      Looking for working code to  get full path of process  - both 32 & 64 bit.
      I tryed this bellow, but it works only for 32-bit processes, even if compiled for x64...
      Thanx for suggestions!
       
      Func _ProcessGetPath($vProcess) ;get the program path done by MrCreatoR Local $iPID = ProcessExists($vProcess) If NOT $iPID Then Return SetError(1, 0, -1) Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID) If NOT IsArray($aProc) OR NOT $aProc[0] Then Return SetError(2, 0, -1) Local $vStruct = DllStructCreate('int[1024]') Local $hPsapi_Dll = DllOpen('Psapi.dll') If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll') If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll') If $hPsapi_Dll = -1 Then Return SetError(3, 0, '') DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _ 'hwnd', $aProc[0], _ 'ptr', DllStructGetPtr($vStruct), _ 'int', DllStructGetSize($vStruct), _ 'int_ptr', 0) Local $aRet = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _ 'hwnd', $aProc[0], _ 'int', DllStructGetData($vStruct, 1), _ 'str', '', _ 'int', 2048) DllClose($hPsapi_Dll) If NOT IsArray($aRet) OR StringLen($aRet[3]) = 0 Then Return SetError(4, 0, '') Return $aRet[3] EndFunc  
    • siva1612
      By siva1612
      I would like to create a window like the one shown below. The requirements are as below
      1. The title bar should be opaque.
      2. The parent window/Main screen will be below the side menu/child window
      3. The left side of the side menu window should be opaque.
      4. The right side should be semi-transparent. 

       
      Any idea to help?