Jump to content

Recommended Posts

Posted

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?

  • Developers
Posted

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted
  On 2/4/2017 at 8:04 AM, Subz said:

Have a look at OnAutoItExitRegister function in the help file.

Expand  

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?

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
Posted
  On 2/6/2017 at 12:57 PM, 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.

Expand  

 

Posted
  On 2/4/2017 at 8: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

Expand  

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.

 

 

  • Developers
Posted
  On 2/8/2017 at 3:45 AM, BetaLeaf said:

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

Expand  

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 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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
×
×
  • Create New...