Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Using subprocess.Popen() in a Windows service

Reply
Thread Tools

Using subprocess.Popen() in a Windows service

 
 
Mark Shewfelt
Guest
Posts: n/a
 
      11-05-2008
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
 
Reply With Quote
 
 
 
 
yomgui
Guest
Posts: n/a
 
      11-06-2008
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Consuming Web Service from WIndows application when WebService is using Custom Service Account ( Create an Application Pool with a Custom Identity) DNB ASP .Net Security 1 01-22-2008 09:08 PM
Error Consuming Web Service from WIndows application when WebService is using Custom Service Account ( Create an Application Pool with a Custom Identity) DNB ASP .Net Web Services 1 01-20-2008 01:47 PM
Indexing services under Windows XP SP2 - Can I disable MS Indexing Service to hasten Google's OR does Google Desktop uses this MS Indexing Service? ricardodefaria Computer Support 6 08-05-2007 04:14 AM
Exposing Unmanaged C++ Windows Service code as a ASP.NET service. =?Utf-8?B?c2h5YW0=?= ASP .Net 2 05-22-2006 01:47 AM
InvocationTargetException when calling "new Service()" in Axis web service to call another web service Michael Averstegge Java 0 01-10-2006 11:05 PM



Advertisments