os.popen problem
Steve Holden
sholden at holdenweb.com
Mon Aug 30 08:21:35 EDT 2004
Matthew K Jensen wrote:
> Ok, this might seem odd as to why I am doing this in this certain way,
> but it's for a very specific purpose, and in so doing needs to be done
> this way. I am writing code on a winbloze box like so:
>
> -----------
> import os
>
> vlvl = os.popen('copy con randomfilename','w')
> vlvl.write('some stuff')
> vlvl.write('some more stuff')
> vlvl.write(chr(0))
> vlvl.close()
>
> -----------
>
> At the next to last line, the command is supposed to complete and give
> output which resembles "\t1 file(s) copied.\r\n". Appearantly this is
> not happening. The last line just hangs there, doing nothing. Is there
> something I am supposed to be doing, or is there some concept that has
> either blown over the top of my head or just simply forgot? Any
> feedback is helpful.
>
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>>
>>> vlvl = os.popen('copy con randomfilename','w')
>>> vlvl.write('some stuff')
>>> vlvl.write('some more stuff')
>>> vlvl.write(chr(0))
>>> vlvl.close()
;oisrulkejhlakjhlkjdh
lkjhlkdjfhglkjdfghldkjh
jhfljksdhldskjghldkjhgldkjgh
^Z
1
>>> ^Z
C:\Documents and Settings\sholden>more randomfilename
;oisrulkejhlakjhlkjdh
lkjhlkdjfhglkjdfghldkjh
jhfljksdhldskjghldkjhgldkjgh
Note that the "copy" command you start with the os.popen() call is
specifically reading from the console, and NOT from the standard input.
Thus everything you write "down the pipeline" disappears into a black
hole. The copy process won't terminate until you send an EOF (CTRL/Z) on
the console, and then the program will temrinate normally.
regards
Steve
More information about the Python-list
mailing list