[Tutor] how popen works?

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Jul 22 00:38:08 CEST 2004


> 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.

Normally it would unless the command itself is set to run in the
background.

> 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.

popen() is used where you need to read the output of the command.
If you just need the return code from the command then os.system()
is easier to use.

> 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' %(local_ccf)
>     pipeFile = os.popen("%s" %str(syncCommand))
>

This would be easier with:

pipefile = popen(syncCommand)

The extra level of string formatting and conversion is doing nothing
useful.

Also to read the results of the command you will need to read the
results of popen like

output = pipefile.read()

Dunno if that helps...

Alan G



More information about the Tutor mailing list