1. Parallelling system_exec
- Posted by Patrick Barnes <mrtrick at gmail.com> Jun 28, 2004
- 452 views
I'm using system_exec in a command-line program (although executing using exw.exe) to run the curl utility a number of times (with a god-awfully long lost of parameters that uploads a file to a particular server, waits for the server to process it, then downloads the result to a file) Problem is, it takes about 2 minutes per instance. How can I run all of them at once? I'm not using win32lib at all, or any external functions yet. -- MrTrick
2. Re: Parallelling system_exec
- Posted by Andy Serpa <ac at onehorseshy.com> Jun 28, 2004
- 417 views
First, download Bernie Ryan's "Win32 Engine" from the archive. Below is an include file I use to spawn child processes without waiting on them before continuing. To use it:
handle = child_process(<command line here>) -- the above runs the program specified by command-line -- and returns a integer handle, or 0 on error -- example: handle = child_process("c:\\curl_dir\\curl.exe -whatever whatever")
If you aren't going to use the handle for anything (sounds like you aren't), then immediately call:
child_close(handle) -- closes the handle only (releases resources), doesn't affect the child program itself
To terminate immediately a child program (abnormal termination), use:
child_kill(handle) -- handle must still be open (it will close it upon termination)
I use the second two procedures because I monitor the child processes via interprocess communication -- doesn't sound like you need that. -- Andy
------------------------------------------------------ include w32engin.ew without warning constant TRUE = 1, FALSE = 0, NULL = 0 object void global function child_process(sequence cmdline) atom piProcInfo, siStartInfo, addr, hChildProcess integer bFuncRetn addr = allocate_string(cmdline) -- command to run child program ("exwc program.exw") -- Set up members of the PROCESS_INFORMATION structure. piProcInfo = struc("PROCESS_INFORMATION") -- Set up members of the STARTUPINFO structure. siStartInfo = struc("STARTUPINFO") put(siStartInfo,"cb",sizeof("STARTUPINFO")) -- Create the child process. bFuncRetn = CreateProcessA({ NULL, -- app name (we use command line instead) addr, -- command-line NULL, -- process security attributes NULL, -- primary thread security attributes FALSE, -- handles are not inherited 0, -- creation flags NULL, -- use parent's environment NULL, -- use parent's current directory siStartInfo, -- STARTUPINFO pointer piProcInfo}) -- receives PROCESS_INFORMATION free(addr) if bFuncRetn = 0 then free_mem(siStartInfo) free_mem(piProcInfo) return 0 -- error else hChildProcess = grab(piProcInfo,"hProcess") void = CloseHandle(grab(piProcInfo,"hThread")) free_mem(siStartInfo) free_mem(piProcInfo) return hChildProcess -- return handle to process end if end function global procedure child_kill(atom hChildProcess) if hChildProcess then void = TerminateProcess({hChildProcess,0}) void = CloseHandle(hChildProcess) end if end procedure global procedure child_close(atom hChildProcess) if hChildProcess then void = CloseHandle(hChildProcess) end if end procedure --------------------------------------------------------
3. Re: Parallelling system_exec
- Posted by Patrick Barnes <mrtrick at gmail.com> Jun 28, 2004
- 413 views
Wait.... I'm writing a script that just has to call an executeable roughly 20 times. All I want is for the code to return immediately from the system call, not wait for the executeable to finish (most of the time is on the server). There are no gui elements to this script at all... I don't want to be shackled to a gui library. What about the win32lib shellExecute? Does it wait for the program to finish? Or what about the "start" moniker. Does it allow parameter passing? On Sun, 27 Jun 2004 22:44:01 -0700, Andy Serpa <guest at rapideuphoria.com> wrote: > > > posted by: Andy Serpa <ac at onehorseshy.com> > > First, download Bernie Ryan's "Win32 Engine" from the archive. Below is an > include file I use to spawn child processes without waiting on them before > continuing. To use it: > > }}} <eucode> > handle = child_process(<command line here>) > > -- the above runs the program specified by command-line > -- and returns a integer handle, or 0 on error > -- example: handle = child_process("c:\\curl_dir\\curl.exe -whatever > whatever") > </eucode> {{{ > > If you aren't going to use the handle for anything (sounds like you aren't), > then immediately call: > > }}} <eucode> > child_close(handle) -- closes the handle only (releases resources), doesn't > affect the child program itself > </eucode> {{{ > > To terminate immediately a child program (abnormal termination), use: > > }}} <eucode> > child_kill(handle) -- handle must still be open (it will close it upon > termination) > </eucode> {{{ > > I use the second two procedures because I monitor the child processes via > interprocess communication -- doesn't sound like you need that. > > -- Andy > > }}} <eucode> > > > without warning > > constant > TRUE = 1, > FALSE = 0, > NULL = 0 > > object void > > global function child_process(sequence cmdline) > atom piProcInfo, siStartInfo, addr, hChildProcess > integer bFuncRetn > > addr = allocate_string(cmdline) -- command to run child program ("exwc > program.exw") > > -- Set up members of the PROCESS_INFORMATION structure. > piProcInfo = struc("PROCESS_INFORMATION") > > -- Set up members of the STARTUPINFO structure. > siStartInfo = struc("STARTUPINFO") > put(siStartInfo,"cb",sizeof("STARTUPINFO")) > > -- Create the child process. > bFuncRetn = CreateProcessA({ > NULL, -- app name (we use command line instead) > addr, -- command-line > NULL, -- process security attributes > NULL, -- primary thread security attributes > FALSE, -- handles are not inherited > 0, -- creation flags > NULL, -- use parent's environment > NULL, -- use parent's current directory > siStartInfo, -- STARTUPINFO pointer > piProcInfo}) -- receives PROCESS_INFORMATION > > free(addr) > > if bFuncRetn = 0 then > free_mem(siStartInfo) > free_mem(piProcInfo) > return 0 -- error > else > hChildProcess = grab(piProcInfo,"hProcess") > void = CloseHandle(grab(piProcInfo,"hThread")) > free_mem(siStartInfo) > free_mem(piProcInfo) > return hChildProcess -- return handle to process > end if > > end function > > global procedure child_kill(atom hChildProcess) > if hChildProcess then > void = TerminateProcess({hChildProcess,0}) > void = CloseHandle(hChildProcess) > end if > end procedure > > global procedure child_close(atom hChildProcess) > if hChildProcess then > void = CloseHandle(hChildProcess) > end if > end procedure > > > > > -- MrTrick
4. Re: Parallelling system_exec
- Posted by Patrick Barnes <mrtrick at gmail.com> Jun 28, 2004
- 409 views
> I'm writing a script that just has to call an executeable roughly 20 > times. All I want is for the code to return immediately from the > system call, not wait for the executeable to finish (most of the time > is on the server). > > There are no gui elements to this script at all... I don't want to be > shackled to a gui library. > > What about the win32lib shellExecute? Does it wait for the program to > finish? Or what about the "start" moniker. Does it allow parameter > passing? > shellExecute (using a no-win32lib hack, searched the forum for info) doesn't seem to be working for me either... it will run a simple program, but it won't take command-line parameters... -- MrTrick
5. Re: Parallelling system_exec
- Posted by Andy Serpa <ac at onehorseshy.com> Jun 28, 2004
- 418 views
Patrick Barnes wrote: > > Wait.... > > I'm writing a script that just has to call an executeable roughly 20 > times. All I want is for the code to return immediately from the > system call, not wait for the executeable to finish (most of the time > is on the server). > > There are no gui elements to this script at all... I don't want to be > shackled to a gui library. > The code I provided does just that -- allows you to run a program without waiting on a return value. No GUI is needed, but it does use the Windows API and Bernie's windows engine. To run something several times without any interaction, just do:
handle = child_process("program.exe") child_close(handle) handle = child_process("program.exe") child_close(handle) handle = child_process("program.exe") child_close(handle) handle = child_process("program.exe") child_close(handle)
All 4 instances will start up nearly simulataneously, and the calling program can go ahead and exit if desired...
6. Re: Parallelling system_exec
- Posted by "Wolf" <wolfritz at king.igs.net> Jun 28, 2004
- 413 views
> shellExecute (using a no-win32lib hack, searched the forum for info) > doesn't seem to be working for me either... it will run a simple > program, but it won't take command-line parameters... If something crazy like this works for me, then..... ? ---- function alloc_str(sequence s) atom mem mem=machine_func(16,length(s)+1) if mem then poke(mem,s) poke(mem+length(s),0) end if return mem end function constant C_INT=#01000004 ,sh32=machine_func(50,"shell32.dll") ,shEx=machine_func(51,{sh32,"ShellExecuteA", {C_INT,C_INT,C_INT,C_INT,C_INT,C_INT},C_INT}) ,action=alloc_str("open") ,prog=alloc_str("cdrecord.exe") ,params=alloc_str(" -v -dummy -data -dev=0,1,0 test.iso") ,dir=alloc_str("d:\\unzipped\\cdrtools\\") atom ret ret=c_func(shEx,{0,action,prog,params,dir,1}) if ret < 33 then printf(1,"shell_error#%d %s\n",{ret,"..oops"}) machine_proc(64,3) end if
7. Re: Parallelling system_exec
- Posted by "Juergen Luethje" <j.lue at gmx.de> Jun 28, 2004
- 423 views
Andy wrote: > Patrick Barnes wrote: >> >> Wait.... >> >> I'm writing a script that just has to call an executeable roughly 20 >> times. All I want is for the code to return immediately from the >> system call, not wait for the executeable to finish (most of the time >> is on the server). >> >> There are no gui elements to this script at all... I don't want to be >> shackled to a gui library. >> > > The code I provided does just that -- allows you to run a program > without waiting on a return value. No GUI is needed, but it does use > the Windows API and Bernie's windows engine. To run something several > times without any interaction, just do: > > }}} <eucode> > handle = child_process("program.exe") > child_close(handle) > handle = child_process("program.exe") > child_close(handle) > handle = child_process("program.exe") > child_close(handle) > handle = child_process("program.exe") > child_close(handle) > </eucode> {{{ > > All 4 instances will start up nearly simulataneously, and the calling > program can go ahead and exit if desired... Why not use system()? It also calls the child processes asynchronously, or am I missing something? The following code works fine on my system (Windows 98):
system("explorer.exe.", 2) system("calc.exe.", 2) system("notepad.exe.", 2) system("charmap.exe.", 2)
Regards, Juergen
8. Re: Parallelling system_exec
- Posted by Andy Serpa <ac at onehorseshy.com> Jun 28, 2004
- 438 views
Juergen Luethje wrote: > Why not use system()? It also calls the child processes asynchronously, > or am I missing something? The following code works fine on my system > (Windows 98): > > <font color="#330033"></font> > <font color="#FF00FF">system</font><font color="#330033">(</font><font > color="#00A033">"explorer.exe."</font><font color="#330033">, 2)</font> > <font color="#FF00FF">system</font><font color="#330033">(</font><font > color="#00A033">"calc.exe."</font><font color="#330033">, 2)</font> > <font color="#FF00FF">system</font><font color="#330033">(</font><font > color="#00A033">"notepad.exe."</font><font color="#330033">, 2)</font> > <font color="#FF00FF">system</font><font color="#330033">(</font><font > color="#00A033">"charmap.exe."</font><font color="#330033">, 2)</font> > <font color="#330033"></font> > system() does not work asynchronously, at least on my system (with the Windows interpreter -- maybe under DOS?). e.g. system("notepad.exe",2) ? 99 -- code not executed until notepad.exe is terminated
9. Re: Parallelling system_exec
- Posted by "Kat" <gertie at visionsix.com> Jun 28, 2004
- 409 views
On 28 Jun 2004, at 13:21, Andy Serpa wrote: > > > posted by: Andy Serpa >ac at onehorseshy.com> > > Juergen Luethje wrote: > > Why not use system()? It also calls the child processes asynchronously, > > or am I missing something? The following code works fine on my system > > (Windows 98): > > > > >font color="#330033">>/font> > > >font color="#FF00FF">system>/font>>font color="#330033">(>/font>>font > > color="#00A033">"explorer.exe.">/font>>font color="#330033">, 2)>/font> >font > > color="#FF00FF">system>/font>>font color="#330033">(>/font>>font > > color="#00A033">"calc.exe.">/font>>font color="#330033">, 2)>/font> >font > > color="#FF00FF">system>/font>>font color="#330033">(>/font>>font > > color="#00A033">"notepad.exe.">/font>>font color="#330033">, 2)>/font> >font > > color="#FF00FF">system>/font>>font color="#330033">(>/font>>font > > color="#00A033">"charmap.exe.">/font>>font color="#330033">, 2)>/font> >font > > color="#330033">>/font> > > > > system() does not work asynchronously, at least on my system (with the Windows > interpreter -- maybe under DOS?). > > e.g. > > system("notepad.exe",2) > > ? 99 -- code not executed until notepad.exe is terminated What about using Al Getz's Display Server to run and communicate with them? Kat
10. Re: Parallelling system_exec
- Posted by "Juergen Luethje" <j.lue at gmx.de> Jun 28, 2004
- 417 views
Andy Serpa wrote: > posted by: Andy Serpa <ac at onehorseshy.com> > > Juergen Luethje wrote: >> Why not use system()? It also calls the child processes asynchronously, >> or am I missing something? The following code works fine on my system >> (Windows 98): ^^^^^^^^^^ >> <font color="#330033"></font> >> <font color="#FF00FF">system</font><font color="#330033">(</font><font >> color="#00A033">"explorer.exe."</font><font color="#330033">, 2)</font> >> <font color="#FF00FF">system</font><font color="#330033">(</font><font >> color="#00A033">"calc.exe."</font><font color="#330033">, 2)</font> >> <font color="#FF00FF">system</font><font color="#330033">(</font><font >> color="#00A033">"notepad.exe."</font><font color="#330033">, 2)</font> >> <font color="#FF00FF">system</font><font color="#330033">(</font><font >> color="#00A033">"charmap.exe."</font><font color="#330033">, 2)</font> >> <font color="#330033"></font> Rob, is this the way the EUforum message board quotes Eu code, that was syntax highlighted in the original post? Is there a way to change this behaviour? It should have been: >> system("explorer.exe.", 2) >> system("calc.exe.", 2) >> system("notepad.exe.", 2) >> system("charmap.exe.", 2) > system() does not work asynchronously, at least on my system (with the > Windows interpreter -- maybe under DOS?). As I wrote, it does so on my *Windows* system. (It does so on my PC under DOS, too). All 4 programs are executed almost simulataneously. Which Windows version do you use (2000 or XP, I believe)? Regards, Juergen
11. Re: Parallelling system_exec
- Posted by Robert Craig <rds at RapidEuphoria.com> Jun 28, 2004
- 424 views
Juergen Luethje wrote: > Rob, is this the way the EUforum message board quotes Eu code, that was > syntax highlighted in the original post? Is there a way to change this > behaviour? When I have time, I might change the way I'm doing the syntax highlighting. It looks ok when first posted on the Message Board, but when you quote it, all that HTML is messy looking, especially via e-mail. Maybe I'll remove the HTML when you quote some colorized code, but I'll leave the eucode ... /eucode tags in place so it will be recolorized for the Message Board but not via e-mail. (If you don't know what I'm talking about, don't worry... I'm just thinking out loud.) Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
12. Re: Parallelling system_exec
- Posted by Andy Serpa <ac at onehorseshy.com> Jun 29, 2004
- 421 views
Juergen Luethje wrote: > > > As I wrote, it does so on my *Windows* system. (It does so on my PC > under DOS, too). All 4 programs are executed almost simulataneously. > Which Windows version do you use (2000 or XP, I believe)? > I understand that you're using Windows, but you didn't say if you were using the Windows interpreter exw.exe (I am) or ex.exe. I'm using WinXP Pro, but I don't think it was any different when I had Win98. The docs seem to indicate that it waits for an exit value from the spawned program...
13. Re: Parallelling system_exec
- Posted by Bob Elia <bobelia200 at netzero.net> Jun 29, 2004
- 431 views
At 06:17 PM 6/28/04 -0700, you wrote: > > >posted by: Andy Serpa <ac at onehorseshy.com> > >Juergen Luethje wrote: > > > > > > As I wrote, it does so on my *Windows* system. (It does so on my PC > > under DOS, too). All 4 programs are executed almost simulataneously. > > Which Windows version do you use (2000 or XP, I believe)? > > >I understand that you're using Windows, but you didn't say if you were >using the Windows interpreter exw.exe (I am) or ex.exe. I'm using WinXP >Pro, but I don't think it was any different when I had Win98. The docs >seem to indicate that it waits for an exit value from the spawned program... I believe Andy is correct.
system("notepad.exe", 2)
This appears not to block because what is happening here is that the command shell called by system() is returning as soon as it has launched notepad.exe, a Win32 program. Try the following:
puts(1, "calling \"system(\"ex.exe\", 2)...\n") system("ex.exe", 2) puts(1, "calling \"system(\"notepad.exe\", 2)...\n") system("notepad.exe", 2) puts(1, "\n\n\n\n") clear_screen() ? 99 while get_key()= -1 do end while
This behaves the same whether I run it with EX.EXE or EXW.EXE ( I think; it's late and I'm tired). The call to system("ex.exe", 2) blocks until you press ENTER. EX.EXE is an extended DOS program and therefore blocks. This all appears to be the same results you would get by typing the names of the programs at the command line in a DOS box. Bob
14. Re: Parallelling system_exec
- Posted by "Elliott S. de Andrade" <quantum_analyst at hotmail.com> Jun 29, 2004
- 429 views
>From: Andy Serpa <guest at RapidEuphoria.com> >Reply-To: EUforum at topica.com >To: EUforum at topica.com >Subject: Re: Parallelling system_exec >Date: Mon, 28 Jun 2004 18:17:47 -0700 > >posted by: Andy Serpa <ac at onehorseshy.com> > >Juergen Luethje wrote: > > > > > > As I wrote, it does so on my *Windows* system. (It does so on my PC > > under DOS, too). All 4 programs are executed almost simulataneously. > > Which Windows version do you use (2000 or XP, I believe)? > > >I understand that you're using Windows, but you didn't say if you were >using the Windows interpreter exw.exe (I am) or ex.exe. I'm using WinXP >Pro, but I don't think it was any different when I had Win98. The docs >seem to indicate that it waits for an exit value from the spawned >program... > This has come up before. http://www.listfilter.com/cgi-bin/esearch.exu?thread=1&fromMonth=6&fromYear=8&toMonth=8&toYear=8&keywords=%22system_exec()%22 AFAICT, there is no guarantee whether system/system_exec are asynchronous or not. It varies between systems, so it would be best if you used shellExecute, or whatever... ~[ WingZone ]~ http://wingzone.tripod.com/