Guest phkappler Posted March 30, 2004 Share Posted March 30, 2004 I'd like to run two simultaneous instances of a file (here: myfile.exe) withRun, %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 Link to comment Share on other sites More sharing options...
Developers Jos Posted March 30, 2004 Developers Share Posted March 30, 2004 (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 EndIfEDIT: The script needs to be compile and run the EXE for it to work!! Edited March 30, 2004 by JdeB 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. Link to comment Share on other sites More sharing options...
Guest phkappler Posted March 30, 2004 Share Posted March 30, 2004 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 ) 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 Link to comment Share on other sites More sharing options...
Developers Jos Posted March 30, 2004 Developers Share Posted March 30, 2004 (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 March 30, 2004 by JdeB 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. Link to comment Share on other sites More sharing options...
ezzetabi Posted April 9, 2004 Share Posted April 9, 2004 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. Link to comment Share on other sites More sharing options...
Recommended Posts