Re: error? Print Preview

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

Juergen,

Thanks for system_wait(), it was pretty much what I needed. It didn't
seem to be returning the correct result codes for me, so I started
playing & I've -finally- found a way to make MEditor both remain
active and [optionally] jump to the ex.err file when a crash happens.
Anyway, the mods I used are below, in case you want them.

It calls doEvents(0) (if available, from win32lib) & goes fully idle
in 1/25th second blocks, so it shouldn't slow anything down too much.

---------------------------[ system_wait.ew
]---------------------------
-- by Juergen Luethje
-- Euphoria 2.3+
-- works like Euphoria's system_exec()

include dll.e
include machine.e

constant
   FALSE =3D 0,
--   INFINITE =3D #FFFFFFFF,   -- Infinite timeout
   FORTYMS=3D40, 			 -- Forty milliseconds, 1/25th of a second
   STILL_ACTIVE=3D259

constant   -- TYPE STARTUPINFO
   cb			   =3D  0,   -- DWORD
-- lpReserved      =3D  4,   -- ASCIIZ PTR
-- lpDesktop       =3D  8,   -- ASCIIZ PTR
-- lpTitle         =3D 12,   -- ASCIIZ PTR
-- dwX             =3D 16,   -- DWORD
-- dwY             =3D 20,   -- DWORD
-- dwXSize         =3D 24,   -- DWORD
-- dwYSize         =3D 28,   -- DWORD
-- dwXCountChars   =3D 32,   -- DWORD
-- dwYCountChars   =3D 36,   -- DWORD
-- dwFillAttribute =3D 40,   -- DWORD
-- dwFlags         =3D 44,   -- DWORD
-- wShowWindow     =3D 48,   -- WORD
-- cbReserved2     =3D 50,   -- WORD
-- lpReserved2     =3D 52,   -- BYTE PTR
-- hStdInput       =3D 56,   -- DWORD
-- hStdOutput      =3D 60,   -- DWORD
-- hStdError       =3D 64,   -- DWORD
SIZEOF_STARTUPINFO =3D 68


constant   -- TYPE PROCESS_INFORMATION
   hProcess    =3D  0,   -- DWORD
   hThread	   =3D  4,   -- DWORD
-- dwProcessId =3D  8,   -- DWORD
-- dwThreadId  =3D 12,   -- DWORD
SIZEOF_PROCESS_INFORMATION =3D 16


constant
   kernel32 =3D open_dll("kernel32.dll"),
   CreateProcess =3D define_c_func(kernel32, "CreateProcessA",
								{C_POINTER, C_POINTER, C_POINTER,
C_POINTER, C_LONG,
								 C_ULONG, C_POINTER, C_POINTER,
C_POINTER, C_POINTER},
								 C_LONG),
   WaitForSingleObject =3D define_c_func(kernel32,
"WaitForSingleObject", {C_ULONG, C_ULONG},
								 C_ULONG),
   CloseHandle =3D define_c_func(kernel32, "CloseHandle", {C_ULONG},
C_LONG),
   GetExitCodeProcess=3Ddefine_c_func(kernel32, "GetExitCodeProcess",
{C_ULONG, C_ULONG},
								 C_ULONG)

global function system_wait (sequence child_process)
-- after:
--
http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/dllpro=
c/base/creating_processes.asp
--
http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/dllpro=
c/base/createprocess.asp
--
http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/dllpro=
c/base/waitforsingleobject.asp

   atom si, pi, child, ret, void, hProc, hThr
atom ec
object junk
integer doevents

   si =3D allocate(SIZEOF_STARTUPINFO)
   poke(si, repeat(0, SIZEOF_STARTUPINFO))
   poke4(si+cb, SIZEOF_STARTUPINFO)

   pi =3D allocate(SIZEOF_PROCESS_INFORMATION)
   poke(pi, repeat(0, SIZEOF_PROCESS_INFORMATION))

   child =3D allocate_string(child_process)

   -- Start the child process.
   if c_func(CreateProcess,
			 {NULL, 	-- No module name (use command line).
			  child,	-- Command line.
			  NULL, 	-- Process handle not inheritable.
			  NULL, 	-- Thread handle not inheritable.
			  FALSE,	-- Set handle inheritance to FALSE.
			  0,		-- No creation flags.
			  NULL, 	-- Use parent's environment block.
			  NULL, 	-- Use parent's starting directory.
			  si,		-- Pointer to STARTUPINFO structure.
			  pi})		-- Pointer to PROCESS_INFORMATION structure.
			  =3D 0 then
	  free(si)
	  free(pi)
	  free(child)
	  return -1 		-- error
   end if

   hProc =3D peek4u(pi+hProcess)
   hThr  =3D peek4u(pi+hThread)

   -- Wait until child process exits.
--   ret =3D c_func(WaitForSingleObject, {hProc, INFINITE})
   ec=3Dallocate(4)
   doevents=3Droutine_id("doEvents")	-- if available
   while 1 do
	  junk=3Dc_func(GetExitCodeProcess, {hProc, ec})
	  ret=3Dpeek4u(ec)
	  if ret!=3DSTILL_ACTIVE then exit end if
	  if doevents!=3D-1 then call_proc(doevents,{0}) end if
	  ret =3D c_func(WaitForSingleObject, {hProc, FORTYMS})
   end while
   free(ec)
   -- Close process and thread handles.
   void =3D c_func(CloseHandle, {hProc})
   void =3D c_func(CloseHandle, {hThr})

   free(si)
   free(pi)
   free(child)
   return ret
end function
------------------------------------------------------------------------

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

Search



Quick Links

User menu

Not signed in.

Misc Menu