Jump to content

Recommended Posts

Afternoon!

Just a quick one as this has dawned on me recently when creating a little program.  When calling an executable I've created like Run(otherapp.exe) from within my executable is there a best practice to ensure things have gone smoothly?  So for example, should I monitor the PID to ensure it runs and closes within an acceptable timeframe?  Or within my other executable should I do EXITs in a certain way after functions and return codes etc?

Could be a silly question but thought I'd ask.

Link to post
Share on other sites
  • Moderators

Most definitely you should be doing some level of error checking when calling an external application from your script. The precise method depends, of course, on the external executable being run, and what the result of its running produces (a new file on the hard drive, an entry in the Event Viewer, a new table in a database, etc.).

As for running an Exit, just realize that is a hard stop. Again, without a hard example of a script you're working on it is difficult to say what you should do in every case. The big question regarding exit code on the script is, are you going to be reporting on that code somewhere else? If there is benefit to it exiting with a specific code as identified by you, then by all means include it. Otherwise, again, you can look at writing to a log file or the Event Viewer for run history reporting.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

OK, noted that sounds good!  So I've inserted a bit of code below just as an example...I have 2 exes that I have created.  First one is used for creating performance monitor stuff and starting stopping etc.  Second one has audit functionality.  Every now and then I want to use one executable to call the other one.  So all I'm doing is something like a run.  Now of course, I have put error logging properly in both executables but I was just wondering if there's a good way to pass this between executables?  Also I was concerned if the performance one failed to respond or stop accordingly for any reason.  That type of thing really.  

<PerformanceCounters.au3> - compiled to performance.exe

Func _logmanStart()
    Local $iPID, $sCommand
    Local $sOutput = ""
    Dim $configIni, $outputPath
    $collectorName = "Test"

    $sCommand = "logman.exe start " & $collectorName
    $iPID = Run('"' & @ComSpec & '" /c' & $sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

    While 1
        $sOutput = StdoutRead($iPID)
        ; Exit the loop if the process closes or StdoutRead returns an error.
        If @error Then ExitLoop
        Select
            Case StringInStr($sOutput, "Cannot create a file when that file already exists.")
                SetError(1,10)
            Case StringInStr($sOutput, "Data collector set was not found.")
                SetError(1,11)
            EndSelect
        WEnd
EndFunc

<Audit.au3> - compiled to audit.exe

Run("performance.exe" /start)

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By SWSSSM
      Hi there,
      maybe someone can help me.
      If automated a script that should xcopy from various paths (all within C:\*\...) to a external Disk (HDD). (Backup data of users who get new pcs win10)
      I tried it several times with windows 10 home/pro any clients and never got any failure. (after the testing was done)
      But when i tried to run it shortly ago on a windows 7  pro x64 client, the script started (as i saw in taskmanagr.exe) but i didn't performed any of the actions when i came down to the xcopy part.
      (in the systemtray, it showd the scipt to start, but it was marked as "paused" and i couldn't stop this. No plan why)
       i inserted/attached the script down here.
      Does anyone know why? any ideas?backup-scrp.au3
      PS:  the tray debug line just added by today (i re-try it tomorrow when i've set up another win7 client to test with)
      PPS: i know my coding-style isn't very optimized
    • By Pike
      Hey Everyone, I haven't been here in a while and recently picked up my old project. Still an FNG!
      To the point: I want to be able to push the button and either play an mp3, open a file, or open an exe program (all with the same button). The problem is that I don't know how to code for that at "case 1"
              Case 1                                                                                                                                             
                  Local $sRead = IniRead("config.ini", "Config", "One", "Default")                                
                  SoundPlay($sRead, @HotKeyPressed)                                                                     <-------------------------------
                  Run($sRead, @HotKeyPressed)                                                                                 <------------------------------- This 'Run' doesn't work even by itself!
      See code below for layout. If you need more information I will attach more code or answer any questions. Any help is greatly appreciated.
       
      Much Respect,
      Pike
       
      Func _HandleButton() $iClickCount += 1 $iTimer = TimerInit() AdlibRegister("CheckButtonPress", $CheckTime) EndFunc Func CheckButtonPress() If TimerDiff($iTimer) < $CheckTime Or $iTimer = 0 Then Return Switch $iClickCount Case 1 Local $sRead = IniRead("config.ini", "Config", "One", "Default") SoundPlay($sRead, @HotKeyPressed) Run($sRead, @HotKeyPressed) Case 2 MsgBox(0, "INFORMATION:", "Choose the file you want designated to this button") Local $sFileOpenDialog = FileOpenDialog(0, @ScriptDir & "\", "All (*.*)", $FD_FILEMUSTEXIST + $FD_MULTISELECT) If @error Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.") EndIf Local $sFileName = InputBox("INFORMATION:", "Please Name Your File?" & @CRLF _ & @CRLF _ & "6 Characters or Less", "") IniWrite(@ScriptDir & "\config.ini", "Config", "One", $sFileOpenDialog) IniWrite(@ScriptDir & "\config.ini", "Config", "NameOne", $sFileName) EndSwitch $iClickCount = 0 AdlibUnRegister() EndFunc  

    • By Skeletor
      Hey All,
      Yes, this is an odd request. 
      But is there a way to bulk up the size of the compiled program? 
      I know many want to reduce it's size, but I want to increase it.
      What methods do you suggest?
    • By dimm
      Is it possible to compile script without any icon resources included?
      When I make exe it uses default system icon of current OS even if I compile as console application.
      On other versions of Windows it looks a little strange

       
      Update:
      It seems that the only way is remove icons from exe after compilation using resource editors like ResHacker.

       
      another bad solution:
      Using corrupted 35 bytes icon file. Windows can't load it and shows default system icon.
      #pragma compile(Icon, broken.ico) broken.ico
    • By Pricehacker
      Hello!
      I want to make a script that changes the filesize of program files while still having them run as usual.
      I tried FileWrite() but then the program wouldnt be recognized as a runnable program, could you guys help me to the right path?
×
×
  • Create New...