Using subprocess.Popen() in a Windows service

Discussion in 'Python' started by Mark Shewfelt, Nov 5, 2008.

  1. 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.Popen 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.Popen( cmd, shell=True, bufsize=128,
    stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
    cwd="C:\\path_to_exe\\" )
    p.wait()
    (modbus_stdin, modbus_stdout)=(p.stdin,p.stdout)
    lines = modbus_stdout.readlines()

    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
     
    Mark Shewfelt, Nov 5, 2008
    #1
    1. Advertising

  2. Mark Shewfelt

    yomgui Guest

    hi,

    this is how i do it:

    from subprocess import Popen, PIPE, call, check_call
    if sys.platform == 'win32':
    net.processWithoutGui = Popen(
    ['python', self.temporaryFilename,'-w'],
    shell=False, cwd=lNetworkDir)
    else:
    net.processWithoutGui = Popen(
    [self.temporaryFilename,'-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.Popen 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.Popen( cmd, shell=True, bufsize=128,
    > stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
    > cwd="C:\\path_to_exe\\" )
    > p.wait()
    > (modbus_stdin, modbus_stdout)=(p.stdin,p.stdout)
    > lines = modbus_stdout.readlines()
    >
    > 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, Nov 6, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. madpython

    subprocess.Popen on Windows

    madpython, Jun 23, 2006, in forum: Python
    Replies:
    3
    Views:
    8,264
    Uri Nix
    Jun 25, 2006
  2. Méta-MCI

    Windows, subprocess.Popen & encodage

    Méta-MCI, May 8, 2007, in forum: Python
    Replies:
    2
    Views:
    406
  3. Tim Golden
    Replies:
    0
    Views:
    480
    Tim Golden
    Oct 7, 2007
  4. Replies:
    8
    Views:
    768
  5. Steven
    Replies:
    7
    Views:
    1,110
    Dennis Lee Bieber
    Sep 13, 2012
Loading...

Share This Page