[Tutor] Python popen command using cat > textfile .... how to terminate
Walker Hale IV
walker.hale.iv at gmail.com
Sun May 17 18:33:40 CEST 2009
On Fri, May 15, 2009 at 12:46 PM, Noufal Ibrahim <noufal at nibrahim.net.in> wrote:
> MK wrote:
>> Hi there,
>> i am using this code to send an "cat > ThisIsMyUrl" with popen.
>> Of cos cat now waits for the CTRL+D command. How can i send this command ?
> Wouldn't it be better if you directly opened the "ThisIsMyUrl" file and
> wrote the text into it rather than rely on shelling out for this?
Agreed. Something like this perhaps?
f = open('ThisIsMyUrl', 'w')
s = sys.stdin.readline()
if len(s) == 0:
break # empty string denotes EOF
Seems to work on my Mac.
Walker Hale <walker.hale.iv at gmail.com>
More information about the Tutor