Using subprocess.Popen() in a Windows service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Shewfelt

    Using subprocess.Popen() in a Windows service

    Hello,

    I am attempting to use Popen() in a Windows service. I have a small
    Win32 .exe that I normally run through the os.popen2() function. I've
    written a class to work with the input and output parameters that are
    passed and captured from this exe. When I use the class outside of a
    service using either subprocess.Pope n or os.popen2 work just fine.

    When I use this class inside a Windows service it doesn't work. It
    doesn't crash the service or anything but there are no values returned
    from the Popen. Here's how I'm calling Popen:

    p = subprocess.Pope n( cmd, shell=True, bufsize=128,
    stdin=subproces s.PIPE, stdout=subproce ss.PIPE, stderr=subproce ss.PIPE,
    cwd="C:\\path_t o_exe\\" )
    p.wait()
    (modbus_stdin, modbus_stdout)= (p.stdin,p.stdo ut)
    lines = modbus_stdout.r eadlines()

    While this doesn't fail there is nothing in the lines variable when it
    finishes.

    I am using Python 2.5 on a Windows XP Professional machine. Any help
    would be greatly appreciated.

    Best Regards,

    Mark Shewfelt
  • yomgui

    #2
    Re: Using subprocess.Pope n() in a Windows service

    hi,

    this is how i do it:

    from subprocess import Popen, PIPE, call, check_call
    if sys.platform == 'win32':
    net.processWith outGui = Popen(
    ['python', self.temporaryF ilename,'-w'],
    shell=False, cwd=lNetworkDir )
    else:
    net.processWith outGui = Popen(
    [self.temporaryF ilename,'-w'],
    shell=False, cwd=lNetworkDir )


    hope it helps

    yomgui



    Mark Shewfelt wrote:
    Hello,
    >
    I am attempting to use Popen() in a Windows service. I have a small
    Win32 .exe that I normally run through the os.popen2() function. I've
    written a class to work with the input and output parameters that are
    passed and captured from this exe. When I use the class outside of a
    service using either subprocess.Pope n or os.popen2 work just fine.
    >
    When I use this class inside a Windows service it doesn't work. It
    doesn't crash the service or anything but there are no values returned
    from the Popen. Here's how I'm calling Popen:
    >
    p = subprocess.Pope n( cmd, shell=True, bufsize=128,
    stdin=subproces s.PIPE, stdout=subproce ss.PIPE, stderr=subproce ss.PIPE,
    cwd="C:\\path_t o_exe\\" )
    p.wait()
    (modbus_stdin, modbus_stdout)= (p.stdin,p.stdo ut)
    lines = modbus_stdout.r eadlines()
    >
    While this doesn't fail there is nothing in the lines variable when it
    finishes.
    >
    I am using Python 2.5 on a Windows XP Professional machine. Any help
    would be greatly appreciated.
    >
    Best Regards,
    >
    Mark Shewfelt

    Comment

    Working...