[Tutor] Python popen command using cat > textfile .... how to terminate
sander.sweers at gmail.com
Fri May 15 12:41:36 CEST 2009
2009/5/15 MK <lopoff at gmx.net>:
> Ok. I explain it once more. Its not about reading the console output of
> the command. Its that i want to put a empty file in my subdirectories
> so that the name of the file is a message or url or something else.
> And if you want an empty file you can do that with
> "cat > IAmAnEmptyFileWithOnlyAName"
> under linux on the CLI.
Ah yes, cat is not what you will wan to use. You can use the unix
touch command or use python's open().
Example touch and subproces (untested!).
command = subprocess.Popen(['touch',
stdout, stderr = command.communicate()
filename = open('/your_filepath/filename', 'w')
> But the problem or advantage of is that you can put some lines in
> the text file if you want. And if youre ready youm must
> terminate the console/terminal with CTRL+D so that cat knows
> that the input is finished.
Like I said above, cat is not the right tool for this. When you use
python's open() you could also write data in the file if needed.
> Actually a very simple way i thought. But maybe not.
It is but only with the right tools ;-)
More information about the Tutor