Sign in to follow this  
Followers 0
Guest phkappler

Q: Get Errorlevel Of Two Concurrent %comspec% Runs

5 posts in this topic

I'd like to run two simultaneous instances of a file (here: myfile.exe) with

Run, %comspec% /e:on /c myfile.exe,, hide

Myfile.exe quits after an unpredictable time. It reports its success or failure in the DOS environment variable errorlevel which I need to parse afterwards.

I can't figure out how to code a script which runs two simultaneous instances of myfile.exe and returns the correct errorlevel for each of them after each ones exit.

In addition, it is important that the file is permanently executed twice, e. g. if one of the both tasks quits, it needs to be restarted immediately. More than two simultaneous tasks are not allowed either.

Any help and suggestions are greatly appreciated.

Best regards

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The below AutoIt3 script will start 2 instances of , in this case notepad and will restart them when they finish...

If Not WinExists("Run#1") Then
   While 1
      AutoItWinSetTitle("Run#1") 
    ; start second instance of the program
      Run('"' & @ScriptFullPath & '"' )
      $RC1 = RunWait(@ComSpec &  ' /e:on /c notepad.exe','',@SW_HIDE)
      FileWriteLine("test.log","rc1:" & $RC1)
   Wend
EndIf
If Not WinExists("Run#2") Then
   While 1
      AutoItWinSetTitle("Run#2") 
      $RC2 = RunWait(@ComSpec &  ' /e:on /c notepad.exe','',@SW_HIDE)
      FileWriteLine("test.log","rc2:" & $RC2)
   Wend
EndIf

EDIT: The script needs to be compile and run the EXE for it to work!!

Edited by JdeB

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

JdeB,

thanks for your awesome fast reply! Your script looks simple yet elegant. I think I'll be able to port it to AutoIt v2. (I've not started with v3 yet because I'm a little frightened of its less intuitive syntax :whistle:)

To my understanding, your solution is to run two instances of the AutoIt Script, each for a single instance of the target application. As the simultaneous double-run will only be a part of a fairly large script with a lot of environment variable declarations and sub routines, I'd prefer a solution from within a single script run.

Do you see a chance to do so?

Best regards

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This is a single program that runs itself for the second time....

You just start it once and it will take care of the rest.

But if you start it multiple times then it will only keep 2 instances active..

Don't think you can ever do it from one single instance because you will only get the returncode back with a runwait.

Edited by JdeB

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

mmn... IF they are console application AND there is at least a little lag between the two AND you are using W2000 and newer THEN

you can use Start "a unique string" "your command" to have a console window with that title and read the DOS variable errorlevel just after that windows disappear.

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0