Re: [PythonCE] Can I execute external programs from PythonCe?

2008-09-06 Thread Adam Walley
Hello,

Just thought I'd put my two cents in...

Igor, have you tried the os.startfile('\mypath\pyprog.exe', 'myAction')
command? Where action is normally 'open', but could be 'print' or some other
option.

It does not give you a reply from the external program, but launches it as
if you had clicked on it from the File Explorer, and it immediately returns
to python. The only problem is that PythonCE might lose focus.

Alex, thanks for the osce file.

Adam

2008/9/6 Alexandre Delattre <[EMAIL PROTECTED]>

> Hi,
>
> Recently I've adapted the module osce.py to use ctypes instead of win32*
> modules.
> 
> Currently there is no os.system function but a systema function that can be
> used this way:
>
> systema('\\full\\path\\to\\program.exe', ['arg1', 'arg2', ...])
>
> Cheers,
> Alexandre
>
> ___
> PythonCE mailing list
> PythonCE@python.org
> http://mail.python.org/mailman/listinfo/pythonce
>
>
___
PythonCE mailing list
PythonCE@python.org
http://mail.python.org/mailman/listinfo/pythonce


Re: [PythonCE] Can I execute external programs from PythonCe?

2008-09-06 Thread Alexandre Delattre

Hi,

Recently I've adapted the module osce.py to use ctypes instead of win32* 
modules.


Currently there is no os.system function but a systema function that can 
be used this way:


systema('\\full\\path\\to\\program.exe', ['arg1', 'arg2', ...])

Cheers,
Alexandre
from ctypes import *
import os

CreateProcess = cdll.coredll.CreateProcessW
WaitForSingleObject = cdll.coredll.WaitForSingleObject
GetExitCodeProcess = cdll.coredll.GetExitCodeProcess
DWORD = HANDLE = c_ulong

class _PI(Structure):
_fields_ = [('hPro', HANDLE),
('hTh', HANDLE),
('idPro', DWORD),
('idTh', DWORD)]

def _create_process(cmd, args):
pi = _PI()
CreateProcess(unicode(cmd), 
  unicode(args),
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  byref(pi))
  
return pi.hPro

def _wait_process(hPro):
WaitForSingleObject(hPro, c_ulong(0x))
return GetExitCodeProcess(hPro)

def _quote(s):
if " " in s:
return '"%s"' %s
return s

def execv(path, args):
if not type(args) in (tuple, list):

raise TypeError, "execv() arg 2 must be a tuple or list"

path = os.path.abspath(path)
args = " ".join(_quote(arg) for arg in args)
_create_process(path, args)

def execve(path, args, env):
execv(path, args)

def systema(path, args):
if not type(args) in (tuple, list):

raise TypeError, "systema() arg 2 must be a tuple or list"

path = os.path.abspath(path)
args = " ".join(_quote(arg) for arg in args)


hPro = _create_process(path, args)

return _wait_process(hPro)
___
PythonCE mailing list
PythonCE@python.org
http://mail.python.org/mailman/listinfo/pythonce