473,666 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

determine if os.system() is done

suppose i'm calling two system processes, one to unzip, and one to
“tail” to get the last line. How can i determine when the first
process is done?

Example:

subprocess.Pope n([r"/sw/bin/gzip","-d","access_log. 4.gz"]);

last_line=subpr ocess.Popen([r"/usr/bin/tail","-n 1","access_log. 4"],
stdout=subproce ss.PIPE).commun icate()[0]

of course, i can try workarounds something like os.system("gzip -d
thiss.gz && tail thiss"), but i wish to know if there's non-hack way to
determine when a system process is done.

Xah
xa*@xahlee.org
http://xahlee.org/

Sep 7 '05 #1
24 2237
Xah Lee wrote:
of course, i can try workarounds something like os.system("gzip -d
thiss.gz && tail thiss"), but i wish to know if there's non-hack way to
determine when a system process is done.


Well, if you use a function of the "popen" family, you get some kind of
return value from the subprocess on your "output" pipe. You should be able
to determine if your subprocess has terminated by examining (parsing) this
output pipe.

If you use os.system(), you should get a single return value (usually "None"
or a error code) that you can use for this task.

In both cases, you may have to use a loop (sleep(x)) to wait for the return
value (and check it) from within your code.

Have a look at the docu of the os.process module for details. (Maybe the
newer "subprocess " module is a better choice...)

HTH

-----------------------------------
Alessandro Bottoni
Sep 7 '05 #2
"Xah Lee" <xa*@xahlee.org > writes:
suppose i'm calling two system processes, one to unzip, and one to
tail to get the last line. How can i determine when the first
process is done? Example: subprocess.Pope n([r"/sw/bin/gzip","-d","access_log. 4.gz"]); last_line=subpr ocess.Popen([r"/usr/bin/tail","-n 1","access_log. 4"],
stdout=subproce ss.PIPE).commun icate()[0] of course, i can try workarounds something like os.system("gzip -d
thiss.gz && tail thiss"), but i wish to know if there's non-hack way to
determine when a system process is done.


Have you tried reading the manual for the subprocess module? You
just *might* find the answer to your question if you look at what
you can do with Popen objects. Actually, just learning about the
exact semantics of the communicate() method might be enought to
solve your problem.
--
Thomas Bellman, Lysator Computer Club, Linkping University, Sweden
"I refuse to have a battle of wits with an ! bellman @ lysator.liu.se
unarmed person." ! Make Love -- Nicht Wahr!

Sep 7 '05 #3
Thomas Bellman wrote:
Have you tried reading the manual for the subprocess module?


han har frskt, men hans tourette tog verhanden:

http://mail.python.org/pipermail/pyt...er/297642.html

</F>

Sep 7 '05 #4
Thomas Bellman wrote:
"Xah Lee" <xa*@xahlee.org > writes:
suppose i'm calling two system processes, one to unzip, and one to
tail to get the last line. How can i determine when the first
process is done?

Example:

subprocess.Po pen([r"/sw/bin/gzip","-d","access_log. 4.gz"]);

last_line=sub process.Popen([r"/usr/bin/tail","-n 1","access_log. 4"],
stdout=subpro cess.PIPE).comm unicate()[0]

of course, i can try workarounds something like os.system("gzip -d
thiss.gz && tail thiss"), but i wish to know if there's non-hack way to
determine when a system process is done.


Have you tried reading the manual for the subprocess module? You
just *might* find the answer to your question if you look at what
you can do with Popen objects.

Oh, come on. Don't you know that all Python documentation is rubbish
and not worth reading, written by IT idiots who throw around useless
jargon and indulge in extreme forms of self-gratification? Someone of
the caliber of Xah Lee would *never* stoop so low as to actually read
the documentation. It is beneath him. Instead, he posts messages to a
group of IT idiots who throw around useless jargon and indulge in
extreme forms of self-gratification in posting answers to questions.

<snip>

JMJ
Sep 7 '05 #5
Xah Lee wrote:
suppose i'm calling two system processes, one to unzip, and one to
“tail” to get the last line. How can i determine when the first
process is done?

Example:

subprocess.Pope n([r"/sw/bin/gzip","-d","access_log. 4.gz"]);

last_line=subpr ocess.Popen([r"/usr/bin/tail","-n 1","access_log. 4"],
stdout=subproce ss.PIPE).commun icate()[0]

of course, i can try workarounds something like os.system("gzip -d
thiss.gz && tail thiss"), but i wish to know if there's non-hack way to
determine when a system process is done.

Xah
xa*@xahlee.org
http://xahlee.org/


I think the idea is you wait for the first call to subprocess.call to
finish before executing the second...

http://docs.python.org/lib/node231.html
call( *args, **kwargs)
Run command with arguments. *Wait for command to complete*, then
return the returncode attribute.

The arguments are the same as for the Popen constructor. Example:

retcode = call(["ls", "-l"])

Sep 7 '05 #6
Yeah, I agree. The Python documentation just merey describes what
arguements a function can take not as much how to use the actual
function.

Sep 7 '05 #7
"Nainto" <Na****@gmail.c om> wrote:
Yeah, I agree. The Python documentation just merey describes what
arguements a function can take not as much how to use the actual
function.


yeah, that's a really relevant criticism when we're talking about a
module that contains one function and one class, and for which the
documentation contains *sixteen* examples.

</F>

Sep 7 '05 #8
[Fredrik Lundh]
han har frskt, men hans tourette tog verhanden:


IMHO it's more likely an Asperger's syndrome.

http://en.wikipedia.org/wiki/Asperger_Syndrome

--
Lars Gustbel
la**@gustaebel. de

Any sufficiently advanced technology is indistinguishab le
from magic.
(Arthur C. Clarke)
Sep 7 '05 #9
Xah Lee wrote:
suppose i'm calling two system processes, one to unzip, and one to
“tail” to get the last line. How can i determine when the first
process is done?

Example:

subprocess.Pope n([r"/sw/bin/gzip","-d","access_log. 4.gz"]);

last_line=subpr ocess.Popen([r"/usr/bin/tail","-n 1","access_log. 4"],
stdout=subproce ss.PIPE).commun icate()[0]

of course, i can try workarounds something like os.system("gzip -d
thiss.gz && tail thiss"), but i wish to know if there's non-hack way to
determine when a system process is done.

Xah
xa*@xahlee.org
http://xahlee.org/


As far as I can tell from the docs (worth reading),
system(command) doesn't return until the process has completed.
It would have to do some fancy footwork to return the exit code
BEFORE the process had completed!

Steve
Sep 7 '05 #10

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

Similar topics

17
6135
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
5
2233
by: Hennie de Nooijer | last post by:
Hi, This is a diffcult issue to explain. I hope to make my problem clear to you. SITUATION I'm building A SLA Query for a customer. This customer has an awkward way to determine the SLA results ;-) Depending on a category which is stored in a headertable (Requests) a field and logic is determined how to get a proper Close_Date. This Close_date can be the closedate of the request. It is also possible that the close_date is a certain...
18
2877
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
3
1908
by: Web Webon | last post by:
Hi everybody! I wonder if this is possible? I need to determine if a client is using "windows classic folders" or anything else. If I instantiate a Shell ActiveX object is there a way of obtaining this information from javascript? (I know that the user will get prompted about allowing such an operation, but I am willing to live with this). Because of the way one of my pages work, I need to know this information in order to "cover up"...
2
1430
by: icodeurs2 | last post by:
I am interested in how to determine if a particular type of hardware has been plugged into Windows XP/2000 programmatically. It could be a service or application running that could detect the new hardware the way XP and 2000 currently do when new hardware is found. I am particularly interested in determining if a flash drive was connected to the system. Your help is greatly appreciated.
2
1711
by: Johannes | last post by:
When you do a webrequest like: Dim objWebRequest As WebRequest = WebRequest.Create(objURI) the returned class can be httpwebrequest, ftpwebrequest or any othe descendant webrequest type that is registered on the system. How can I determine which type is returned. I tried if (objWebRequest is System.Net.HttpWebRequest) then ..... But the system says I am not allowed to use types in expressions. --
3
11573
by: Developer in California | last post by:
I am working on developing a generic Web framework using Master Pages in ASP.NET 2.0. What I have done is created a PageRenderer class which has a public method which will retrieve the path of the content I want to execute based on the name of the asp:Content control. As shown in the code snippet below, to get the content I want to display, I call the GetContentPagePath public method in PageRenderer passing a string duplicating the value...
9
2677
by: | last post by:
I am interested in scanning web pages for content of interest, and then auto-classifying that content. I have tables of metadata that I can use for the classification, e.g. : "John P. Jones" "Jane T. Smith" "Fred Barzowsky" "Department of Oncology" "Office of Student Affairs" "Lewis Hall" etc. etc. etc. I am wondering what the efficient way to do this in code might be. The dumb and brute-force way would be to loop through the content...
3
13234
by: Giampaolo Rodola' | last post by:
Hi, I'd like to know if there's a way to determine which is the best buffer size to use when you have to send() and recv() some data over the network. I have an FTP server application which, on data channel, uses 8192 bytes as buffer for both incoming and outgoing data. Some time ago I received a report from a guy who stated that changing the buffers from 8192 to 4096 results in a drastical speed improvement. I tried to make some tests...
1
8550
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
8638
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
7381
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 projectplanning, coding, testing, and deploymentwithout 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
6191
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
5662
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
4193
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...
1
2769
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
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
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.