Jump to content

Recommended Posts

ur

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
Subz

Have a look at OnAutoItExitRegister function in the help file.

Share this post


Link to post
Share on other sites
Jos

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                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
ur
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
Subz

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
ur

_ProgressRunCommand  , I got this file from below UDF 

 

 

Share this post


Link to post
Share on other sites
Subz

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
Subz

Please see modification in code above.

Share this post


Link to post
Share on other sites
ur
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
BetaLeaf
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
Jos
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 

  • Like 1

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

Share this post


Link to post
Share on other sites
BetaLeaf

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

    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry after your permission
      I found a function to get the special line commands for any operation
      It requires the name of the process to be searched
      I want to use it to know the process
      Is this possible with this function
      Here is the code
       
      Func commandLineGet($proc, $strComputer=".")
      dim $array[1]
      local $ArrayNumber
      local $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
      local $oProcessColl = $oWMI.ExecQuery("Select * from Win32_Process where Name= " & '"'& $Proc & '"')
      local $Process
      For $Process In $oProcessColl
      $Process = $Process.Commandline
          ReDim $Array[UBound($Array)+1]
      $ArrayNumber = UBound($Array)-1
      $array[$ArrayNumber] = $Process
      Next
      $ArrayNumber = UBound($Array)-1
      $array[0] = $ArrayNumber
      return $array
      EndFunc
    • simy8891
      By simy8891
      Hi guys,
      It's been a while since I wrote my last message here and a while since I used AutoIt. I'm currently sort of desperate and I'm trying to find some help in regards of getting the network usage per process!
      I'm not interested in the total network usage of the NIC, but only on a specific PID's network utilization. They idea is to collect the amount of traffic uploaded and downloaded by a list of specific processes. So far Process Hacker and Process Explorer are capable of getting what I need, but I need to use these numbers in another script so they're sort of useless to me. I can't seem to find a way around it.
      Any idea, help is greatly appreciated.
      Thanks
    • ur
      By ur
      with the below code, I am keeping waiting for a particular file and waiting in the background.
      While $i <> 10 Sleep(60000) If FileExists(@ScriptDir&"\Binaries.ini") then --some processing-- $i = 10 endif WEnd I thought keeping the Sleep will freeze the process from resources but the CPU being uilized.But it is taking 47%.
      How to free this CPU usage also.?

    • ur
      By ur
      With  ProcessList ( ["name"] )  we are able to get the running process list from the local machine.
       
      Is there anyway to get the list from Remote machine, more precisely to get to know the status whether a particular application is running or not on remote machine using AutoIT?
       
      We can implement through PSList.exe, but again we need to parse the text of it to read the output.
      Is there any direct UDF in AutoIT?
    • Nareshm
      By Nareshm
      If Process exits then end process and ;Some code here {1}
       
      If Process does not exits then ; My {1} Code
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.