472,145 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

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.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
Nov 5 '08 #1
1 8048
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
Nov 6 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Darren Dale | last post: by
3 posts views Thread by madpython | last post: by
5 posts views Thread by Grant Edwards | last post: by
12 posts views Thread by Eric_Dexter | last post: by
9 posts views Thread by Phoe6 | last post: by
12 posts views Thread by bhunter | last post: by
25 posts views Thread by Jeremy Banks | last post: by
reply views Thread by Eric Carlson | last post: by
reply views Thread by Saiars | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.