Re: Parallelling system_exec

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu