473,474 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

subprocess returncode always None

Dear All,

I'm currently working on a project that needs to collect the output of
the JHOVE application. More information about the application is
available at this website:

http://hul.harvard.edu/jhove/

The application is written in Java and is executed by a shell script.
There are occasions where this application may get stuck in an
infinite loop. For this reason I've been trying to implement a simple
class that I can use to execute the JHOVE application and if it
doesn't complete in the required period of time to raise an exception
and kill the process.

The class is as follows, apologies for the odd line wrapping.

<snip>
class niceSubprocess(object):
"""
A class that implements a call to the subprocess method with a timeout
- command, the command to execute
- params, the parameters to pass to the application
- timeout, the amount of time in seconds to wait
"""
def executeCommand(self, command, params, timeout):
try:
timeElapsed = 0

process = subprocess.Popen((command, params), stdin =
subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE,
close_fds = True)

while process.poll() == None and timeElapsed < timeout:
print process.poll()
#print process.stdout.read()
timeElapsed = timeElapsed + 1
time.sleep(1)

if process.poll() == None:
# kill off the process, and don't be terribly nice about it
os.kill(process.pid, signal.SIGKILL)
raise timeoutError, timeout
else:
if process.stdout.read() == "":
raise executeError, process.stderr.read()
else:
return process.stdout.read()

except Exception, errorInfo:
# pass the exception to the calling code
raise errorInfo

</snip>

I'm running this on Linux and through the use of top can see the JAVA
process start and complete. The problem I have is that process.poll()
always returns None, even though the application has successfully ran
and returned output.

Can anyone shed some light on why the call to the shell script always
returns None as a return code?

With thanks.

-Corey

--
Corey Wallis
RUBRIC Technical Officer
University of Southern Queensland
http://www.rubric.edu.au
http://techxplorer.wordpress.com
Jul 9 '06 #1
0 2545

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

Similar topics

0
by: Christoph Haas | last post by:
Evening, I'm having trouble with running a process through Python 2.4's subprocess module. Example code: ======================================================== def run(command): run =...
2
by: Jim | last post by:
Hello, I need a program that will traverse a directory tree to ensure that there are unix-style line endings on every file in that tree that is a text file. To tell text files from others I...
4
by: 7stud | last post by:
Hi, What is the difference between: 1) getting the returncode directly from the subprocess object 2) calling poll() on the subprocess object? Here is an example:
12
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...
3
by: jakub.hrozek | last post by:
Hello, My program uses the subprocess module to spawn a child and capture its output. What I'd like to achieve is that stdout is parsed after the subprocess finishes, but anything that goes to...
4
by: grayaii | last post by:
There are so many threads on this subject, but I ran across a situation on Windows that I can't figure out. I'm trying to run this little command-line exe and when I launch like this, it hangs:...
2
by: rparimi | last post by:
I am trying to redirect stderr of a process to a temporary file and then read back the contents of the file, all in the same python script. As a simple exercise, I launched /bin/ls but this doesn't...
7
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...
0
by: Albert Hopkins | last post by:
On Mon, 2008-11-17 at 15:27 -0800, rowen wrote: subprocess.call = call(*popenargs, **kwargs) Run command with arguments. Wait for command to complete, then return the returncode attribute. ...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
1
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...
0
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...
0
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...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.