473,698 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Unable to start a process with subprocess Popen()

On Mon, Sep 8, 2008 at 11:50 AM, <du**********@g mail.comwrote:
Hi,

I'm using the subprocess module's Popen() to start a batch file. This
batch file basically calls an exe which also gets started.
Unfortunately, this does not produce any results. I looked into the
Task bar that this exe has started but it does not consume and cpu so
I believet that this exe is not working.
I used the following command to start the batch fiile:

testing = subprocess.Pope n([batchFilePath], \
shell = True, \
stdout = subprocess.PIPE , \
stderr = subprocess.PIPE ).communicate()[0]
batchFilePath is the path of the batch file.

--
Regrads,
Rajat
Ok, I re-phrase my question:

there is a batch file that executes a exe file. The batch just works
if run from command prompt and produces output to standard output and
the file.

Now, I try to call the same batch file from subprocess.Pope () call.
The batch file gets called and that internally also calls the exe
file.

But, the exe just runs forever i.e. hangs and does not produces output
, atleast not to the file.

Please suggest is there is something wrong with the above code.

Regards,
Rajat
Sep 8 '08 #1
2 2740
aha
On Sep 8, 7:23*am, dudeja.ra...@gm ail.com wrote:
On Mon, Sep 8, 2008 at 11:50 AM, *<dudeja.ra...@ gmail.comwrote:
Hi,
I'm using the subprocess module's Popen() to start a batch file. This
batch file basically calls an exe which also gets started.
Unfortunately, this does not produce any results. I looked into the
Task bar that this exe has started but it does not consume and cpu so
I believet that this exe is not working.
I used the following command to start the batch fiile:
testing = subprocess.Pope n([batchFilePath], \
* * * * * * * * * * * * * * * * * shell = True, \
* * * * * * * * * * * * * * * * * stdout = subprocess.PIPE , \
* * * * * * * * * * * * * * * * * stderr = subprocess.PIPE ).communicate()[0]
batchFilePath is the path of the batch file.
--
Regrads,
Rajat

Ok, I re-phrase my question:

there is a batch file that executes a exe file. The batch just works
if run from command prompt and produces output to standard output and
the file.

Now, I try to call the same batch file from subprocess.Pope () call.
The batch file gets called and that internally also calls the exe
file.

But, the exe just runs forever i.e. hangs and does not produces output
, atleast not to the file.

Please suggest is there is something wrong with the above code.

Regards,
Rajat
Hello Rajat,
I would take a look at the thread below, it might help it might not:

http://groups.google.com/group/comp....e15c9c88a5efdc

Also, if you post a larger section of the code I might be able to give
you a hand. Once you've run the testing = subprocess.Pope n()

make sure you use a testing.wait()
Sep 8 '08 #2
En Mon, 08 Sep 2008 13:35:21 -0300, <du**********@g mail.comescribi ó:
cmd = subprocess.Pope n([batchFilePath], \
shell = True, \
stdin = subprocess.PIPE ,
stdout = subprocess.PIPE , \
stderr = subprocess.PIPE \
)
cmd.stdin.close ()
outPipe, errPipe = PipeThread(cmd. stdout),
PipeThread(cmd. stderr)
outPipe.run(), errPipe.run()
retcode = cmd.wait()
out, err = outPipe.getOutp ut(), errPipe.getOutp ut()

Although, this solved my problem. But I know there is no need for using
threading in this problem. This problem could've been solved just by the
subprocess module.

I'm unnecessarily using the threading module.
Not only that, you're misusing the Thread class. To actually create a
separate execution thread, you should call outPipe.start() instead of
outPipe.run() (same for errPipe).
Note that if your batch file emits a large output it really may be
necesary to use a separate thread to read the output.

--
Gabriel Genellina

Sep 9 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2170
by: Earl Eiland | last post by:
The command string consists of "filename.exe instruction1 instruction2 ...." It works in subprocess, but in process, returns the error "can't find the file instruction1". How do I pass command line instructions in process.Process? I tried a list with the same result. If you're wondering why I'm switching, it's because I'm working with a poorly behaved 3rd party program that causes a severe memory leak, and I
5
7953
by: Natan | last post by:
Hi. I have a python script under linux where I poll many hundreds of interfaces with mrtg every 5 minutes. Today I create some threads and use os.system(command) to run the process, but some of them just hang. I would like to terminate the process after 15 seconds if it doesn't finish, but os.system() doesn't have any timeout parameter. Can anyone help me on what can I use to do this?
8
6516
by: cypher543 | last post by:
This has been driving me insane for the last hour or so. I have search everywhere, and nothing works. I am trying to use the subprocess module to run a program and get its output line by line. But, it always waits for the process to terminate and then return the output all at once. Can someone please show me some code that actually works for this sort of thing? It doesn't even have to use the subprocess module. Don't worry if the code...
13
5113
by: bayer.justin | last post by:
Hi, I am trying to communicate with a subprocess via the subprocess module. Consider the following example: <subprocess.Popen object at 0x729f0> Here hey is immediately print to stdout of my interpreter, I did not type in the "hey". But I want to read from the output into a string, so I do
2
6274
by: Greg Ercolano | last post by:
When I use os.popen(cmd,'w'), I find that under windows, the stdout of the child process disappears, instead of appearing in the DOS window the script is invoked from. eg: C:\type foo.py import os import sys file = os.popen("nslookup", 'w') file.write("google.com\n") file.close()
12
4527
by: bhunter | last post by:
Hi, I've used subprocess with 2.4 several times to execute a process, wait for it to finish, and then look at its output. Now I want to spawn the process separately, later check to see if it's finished, and if it is look at its output. I may want to send a signal at some point to kill the process. This seems straightforward, but it doesn't seem to be working. Here's my test case:
0
811
by: dudeja.rajat | last post by:
Hi, I'm using the subprocess module's Popen() to start a batch file. This batch file basically calls an exe which also gets started. Unfortunately, this does not produce any results. I looked into the Task bar that this exe has started but it does not consume and cpu so I believet that this exe is not working. I used the following command to start the batch fiile:
7
6233
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke this shell script using the Subprocess module. Here is my code: def resultFromRunning_(command):
9
15529
by: Catherine Moroney | last post by:
I have one script (Match1) that calls a Fortran executable as a sub-process, and I want to write another script (Match4) that spawns off several instances of Match1 in parallel and then waits until they all finish running. The only way I can think of doing this is to call it as a sub-process, rather than directly. I'm able to get Match1 working correctly in isolation, using the subprocess.Popen command, but calling an instance of Match1...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.