Can I execute external programs from PythonCe?

View: New views
6 Messages — Rating Filter:   Alert me  

Parent Message unknown Can I execute external programs from PythonCe?

by Igor Kaplan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi pythonce experts,
[Igor Kaplan]
  Would like to ask for the suggestion, is there any way to execute the
external process from pythonce code? There is the os.exec* functions,
however as I understand, they will terminate the current python process and
run the external application. I would need to start the external program and
still be able to continue with my python code.
  If it is more complicated then just calling one function, for example if I
need to create new thread and so on,  I would so much appreciate the little
code example.

  Many, many thanks in advance.

   Igor.

_______________________________________________
PythonCE mailing list
PythonCE@...
http://mail.python.org/mailman/listinfo/pythonce

Parent Message unknown Re: Can I execute external programs from PythonCe?

by René Dudfield :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi,

this page might help:

http://docs.python.org/lib/module-subprocess.html


I don't know if it works on CE though.


cu,

On Thu, Sep 4, 2008 at 8:29 PM, Igor Kaplan <igor_kaplan@...> wrote:

> Hi pythonce experts,
> [Igor Kaplan]
>  Would like to ask for the suggestion, is there any way to execute the
> external process from pythonce code? There is the os.exec* functions,
> however as I understand, they will terminate the current python process and
> run the external application. I would need to start the external program and
> still be able to continue with my python code.
>  If it is more complicated then just calling one function, for example if I
> need to create new thread and so on,  I would so much appreciate the little
> code example.
>
>  Many, many thanks in advance.
>
>   Igor.
>
> _______________________________________________
> PythonCE mailing list
> PythonCE@...
> http://mail.python.org/mailman/listinfo/pythonce
>
_______________________________________________
PythonCE mailing list
PythonCE@...
http://mail.python.org/mailman/listinfo/pythonce

Parent Message unknown Re: Can I execute external programs from PythonCe?

by jabapyth :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think what you want is os.startfile

On Thu, Sep 4, 2008 at 6:29 AM, Igor Kaplan <igor_kaplan@...> wrote:
Hi pythonce experts,
[Igor Kaplan]
 Would like to ask for the suggestion, is there any way to execute the
external process from pythonce code? There is the os.exec* functions,
however as I understand, they will terminate the current python process and
run the external application. I would need to start the external program and
still be able to continue with my python code.
 If it is more complicated then just calling one function, for example if I
need to create new thread and so on,  I would so much appreciate the little
code example.

 Many, many thanks in advance.

  Igor.

_______________________________________________
PythonCE mailing list
PythonCE@...
http://mail.python.org/mailman/listinfo/pythonce


_______________________________________________
PythonCE mailing list
PythonCE@...
http://mail.python.org/mailman/listinfo/pythonce

Parent Message unknown Re: Can I execute external programs from PythonCe?

by Alexandre Delattre :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Recently I've adapted the module osce.py to use ctypes instead of win32*
modules.
<http://mail.python.org/pipermail/pythonce/2005-January/000948.html>
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(0xffffffff))
    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@...
http://mail.python.org/mailman/listinfo/pythonce

Re: Can I execute external programs from PythonCe?

by Adam Walley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 <alexandre.delattre@...>
Hi,

Recently I've adapted the module osce.py to use ctypes instead of win32* modules.
<http://mail.python.org/pipermail/pythonce/2005-January/000948.html>
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@...
http://mail.python.org/mailman/listinfo/pythonce



_______________________________________________
PythonCE mailing list
PythonCE@...
http://mail.python.org/mailman/listinfo/pythonce

Parent Message unknown Re: Can I execute external programs from PythonCe?

by Igor Kaplan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Alexandre and all for the help. The os.StartFile and os.systema are
exactly what I needed, specially since systema takes arguments.

  Thanks so much.
----------------------------------------------------------------------

Date: Sat, 06 Sep 2008 13:29:25 +0200
From: Alexandre Delattre <alexandre.delattre@...>
Subject: Re: [PythonCE] Can I execute external programs from PythonCe?
To: pythonce@...
Message-ID: <48C26995.9010707@...>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"

Hi,

Recently I've adapted the module osce.py to use ctypes instead of win32*
modules.
<http://mail.python.org/pipermail/pythonce/2005-January/000948.html>
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: osce.py
Type: text/x-python
Size: 1547 bytes
Desc: not available
URL:
<http://mail.python.org/pipermail/pythonce/attachments/20080906/e52a55e2/att
achment-0001.py>

_______________________________________________
PythonCE mailing list
PythonCE@...
http://mail.python.org/mailman/listinfo/pythonce