Capturing ERRORLEVEL from 8 processes launched with Run

Get help with using AutoHotkey and its commands and hotkeys
Posts: 1
Joined: 18 Mar 2020, 21:54

Capturing ERRORLEVEL from 8 processes launched with Run

18 Mar 2020, 22:20

I am 95% through a GUI "application" that is a front end to two other programs: one Windows app that I control with mouse clicks and sent keystrokes (so far so good) and one CLI app.
I need to launch the CLI app EIGHT times so they all run in parallel. Like this:

Code: Select all

	Run, "do_something.exe Parameter1 ConstStringParameter"
	Run, "do_something.exe Parameter2 ConstStringParameter"
	Run, "do_something.exe Parameter3 ConstStringParameter"
	Run, "do_something.exe Parameter4 ConstStringParameter"
The purpose of all of this is to update 8 devices simultaneously so that it does not take a year to do 1000 of them (yes, 1000). Needless to say there is a bunch of stuff that happens before and after and all that works great.
I need to find a way to capture the error code that do_something.exe returns so I know if the update was successful.

I can package the CLI stuff in a batch file, capture the %ERRORLEVEL% that is returned and if it's != 0, write it to a file so I know which one failed. AHK has SOOOOOO many features, maybe there is an easier (or more elegant) way??

BTW, this is my first script and I am astonished at how much I can do in such a short time.

User avatar
Posts: 301
Joined: 11 Aug 2016, 02:32
GitHub: lmstearn

Re: Capturing ERRORLEVEL from 8 processes launched with Run

19 Mar 2020, 08:11

Hi @MisterPi, and welcome!
One way might be to put the {cmd_arg, PID} pairs into an object array and run a timer until all the PID values in the array are zero. Possible choices of output include, GUI => listview, Gui, HTML table, Tray tip, Email or the recommended HTML report to view in your favourite browser.
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
Posts: 152
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Capturing ERRORLEVEL from 8 processes launched with Run

27 Mar 2020, 01:10

To capture the errorcode of an external process you must use RunWait. In that way your processes run sequentially what you do not want (1000 instead of 8).

First possibility I see is:
run 1 to 8 different named AutoHotkey scripts of equal function, but using different named variables and filenames, that execute the RunWait. Example:
Run 1 to execute RunWait 7 and 8
Run 1 to execute RunWait 5 and 6
Run 3 to execute RunWait 3 and 4
Run 4 to execute RunWait 1 and 2
Your main script then waits for the 8 files with the errorcodes to be complete.

If you really need 1000 processes you can extend this method into a tree - Run to Run to ... RunWait

Another possibility, more elegant but more difficult:
use AutuHotkey_H, it can run multiple threads in parallel - one of its main benefits - this forum has help for it in special parts
(but I think it's not useful to start 1000 threads at one time)


Return to “Ask For Help”

Who is online

Users browsing this forum: akaza_dorian, Google [Bot], NaNoMister, SashaChernykh, Scr1pter and 392 guests