Subprocess or Process or OMG!!

rh0dium steven.klass at gmail.com
Thu May 18 18:47:59 EDT 2006


Hi all,

Here I was happily coming to working thinking - OK I need to create a
wrapper for a tool (UNIX) which does nothing but lauch the end tool and
send a sql instert letting the db know the tool was launched (Can we
say Big Brother..).  Some of the tools are very long running with lots
of data others are small and very fast..  So I started down my
traditional approach - Check google groups for the answer.  I quickly
became aware of how challenging this actually is.  See my approach was
simple

Tool name = FOOBAR
Symbolically link FOOBAR to my Wrapper.py

1.  Get the args and some other key data (user, cwd, etc)
2.  Fork this process and get FOOBAR running (time is of essense of
course)
3.  On the side submit a mySQL call saying what happened...

Sounds simple and I thought I was ready to go.. Until google groups...

http://groups.google.com/group/comp.lang.python/browse_frm/thread/4a2766a16e67cec8/79e4b404b4f0e1ff?lnk=st&q=Python+Fork+Wrapper&rnum=3#79e4b404b4f0e1ff

OK so now I need to think about I/O redirection hmmm OK More data..
People have dealt with this - but most of it's dated..

Wait import subprocess..  Looks promising hey some has really used
this..

http://www.dalkescientific.com/writings/diary/archive/2005/04/12/wrapping_command_line_programs.html
http://www.third-bit.com/swc2/lec/integrate.html
http://www.easysw.com/~mike/cups/strfiles/1648/smtp

Needless to say this is much more complex than what I was "hoping" for.
 Has anyone solved this in a generic approach..

    #!/usr/bin/env python

    import os,sys,string
    import subprocess

    argc = len(sys.argv)

    # Yes I move all exe's to the .bin direcotory
    sys.argv[0]=os.path.join(os.getcwd() + "/.bin/" +
os.path.basename(sys.argv[0]))

    cmd = string.join(sys.argv," ")
    subprocess.Popen( cmd )

This has several problems - least of which args aren't working....  Has
anyone really tried this approach?




More information about the Python-list mailing list