473,803 Members | 3,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subprocess or Process or OMG!!

Hi all,

Here I was happily coming to working thinking - OK I need to create a
wrapper for a tool (UNIX) which does nothing but lauch the end tool and
send a sql instert letting the db know the tool was launched (Can we
say Big Brother..). Some of the tools are very long running with lots
of data others are small and very fast.. So I started down my
traditional approach - Check google groups for the answer. I quickly
became aware of how challenging this actually is. See my approach was
simple

Tool name = FOOBAR
Symbolically link FOOBAR to my Wrapper.py

1. Get the args and some other key data (user, cwd, etc)
2. Fork this process and get FOOBAR running (time is of essense of
course)
3. On the side submit a mySQL call saying what happened...

Sounds simple and I thought I was ready to go.. Until google groups...

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

OK so now I need to think about I/O redirection hmmm OK More data..
People have dealt with this - but most of it's dated..

Wait import subprocess.. Looks promising hey some has really used
this..

http://www.dalkescientific.com/writi..._programs.html
http://www.third-bit.com/swc2/lec/integrate.html
http://www.easysw.com/~mike/cups/strfiles/1648/smtp

Needless to say this is much more complex than what I was "hoping" for.
Has anyone solved this in a generic approach..

#!/usr/bin/env python

import os,sys,string
import subprocess

argc = len(sys.argv)

# Yes I move all exe's to the .bin direcotory
sys.argv[0]=os.path.join(o s.getcwd() + "/.bin/" +
os.path.basenam e(sys.argv[0]))

cmd = string.join(sys .argv," ")
subprocess.Pope n( cmd )

This has several problems - least of which args aren't working.... Has
anyone really tried this approach?

May 18 '06 #1
3 1235
rh0dium wrote:
Needless to say this is much more complex than what I was "hoping" for.
Has anyone solved this in a generic approach..

#!/usr/bin/env python

import os,sys,string
import subprocess

argc = len(sys.argv)

# Yes I move all exe's to the .bin direcotory
sys.argv[0]=os.path.join(o s.getcwd() + "/.bin/" +
os.path.basenam e(sys.argv[0]))

cmd = string.join(sys .argv," ")
subprocess.Pope n( cmd )

This has several problems - least of which args aren't working.... Has
anyone really tried this approach?


Did you read the documentation? It explains how to pass the command line (hint:
it's a list, not a string).

http://docs.python.org/lib/module-subprocess.html

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

May 18 '06 #2
rh0dium wrote:
This has several problems - least of which args aren't working.... Has
anyone really tried this approach?


No, they just wrote the code for the hell of it. :)

Seriously though, you may want to consider using the popen2 module.
Then you'll be able to wait on the subprocess to return and check the
return code, plus you could do your DB update first then go into a
wait() to check for success.

-B

May 19 '06 #3
ROTFLMAO - Thanks --- I "meant" has anyone done the wrapper approach
before!! Not has anyone used the code.. hahah nice!!

subprocess also has the wait object. I think I like this better than
popen2 (which I have used in the past) for a number of reasons but
primarily it's simplicity. Having said that, I don't think I want to
use the wait object because I am afraid the db query in some cases may
take longer than the command.. That would leave the user wondering
what's going on.. Only testing will tell though..

Thanks Robert - yeah I checked the docs and figured out that it takes a
list shortly after I sent the post.

May 19 '06 #4

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

Similar topics

0
2500
by: Dana Morris | last post by:
Call for Participation OMG's First Annual Software-Based Communications (SBC) Workshop: From Mobile to Agile Communications http://www.omg.org/news/meetings/SBC2004/call.htm September 13-16, 2004 Washington, DC USA Introduction
18
4897
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
3
5508
by: Darren Dale | last post by:
I'm a developer on the matplotlib project, and I am having trouble with the subprocess module on windows (Python 2.4.2 on winXP). No trouble to report with linux. I need to use _subprocess instead of pywin32, but my trouble exists with either option: import subprocess process = subprocess.Popen(, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) stat = process.wait() print process.stdout.read()
0
2646
by: Corey Wallis | last post by:
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
8
6523
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...
9
6498
by: Phoe6 | last post by:
Hi all, Consider this scenario, where in I need to use subprocess to execute a command like 'ping 127.0.0.1' which will have a continuous non- terminating output in Linux. # code # This hangs at this point. How should I handle these kind of commands (ping 127.0.0.1) with
12
4541
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:
25
2798
by: Jeremy Banks | last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the Popen class in the subprocess module. Popen sounds like the a suitable name for a function that created a subprocess, but the object itself is a subprocess, not a "popen". It seems that it would be more accurate to just name the class Subprocess, can anyone explain why this is not the case? Thank you.
7
6240
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):
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10550
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10295
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9125
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...
0
5501
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
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2972
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.