{Spam?} [Tutor] how popen works? (original) (raw)

Bob Gailer bgailer at alum.rpi.edu
Wed Jul 21 20:57:46 CEST 2004


At 09:15 AM 7/21/2004, Larry Blair wrote:

I am new to Python and have inherited some difficult code. I am expanding the functionallity because I can read and figure out what is already there. I just don't have enough background with Python to know how and why some things work the way they to.

My script is shutting down an Oracle database, updating snapshots on an EMC san, and then restarting the Oracle database. To restart the database I call, via popen, a SQLPlus script, this script takes about 90 seconds to execute. I thought that Python at the popoen line would wait until the SQLPlus script was finished and then continue with the next line of code. I want to do some error trapping AFTER the database us running. Python however sends the SQLPlus script and then continues executing the rest of the program. Am I not understanding what popen does or is there a parameter I need to send to it to pause until it is finished, or is there a better way of "shelling" out to the OS and exeuting commands. Here are examples of what I have tried. Both commands work the same - send the command to the OS and comes right back and finishes running the script.

"The return value [of popen] is an open file object connected to the pipe, which can be read." So, after:

 pipeFile = os.popen("%s" %str(syncCommand))

put:

 x = pipeFile.readline() # this should wait until the process returns 

output or terminates.

If there are several lines of output, use readlines() or process readline in a loop.

status = pipeFile.close() # to get the exit status.

We have Win2000 as an OS

1. in this I create a cmd window and with the /c tell it to close after sqlplus is finished syncCommand = 'cmd /c sqlplus /nolog @%s' %(localccf) pipeFile = os.popen("%s" %str(syncCommand))

2. in this I directly call sqlplus syncCommand = 'sqlplus /nolog @%s' %(localccf) pipeFile = os.popen("%s" %str(syncCommand)) Thanks for any insight to this Larry


Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is confidential privileged and/or exempt from disclosure under applicable law. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Thank you.


Tutor maillist - Tutor at python.org http://mail.python.org/mailman/listinfo/tutor

Bob Gailer bgailer at alum.rpi.edu 303 442 2625 home 720 938 2625 cell



More information about the Tutor mailing list