[Tutor] interacting with shell

Paul Tremblay phthenry@earthlink.net
Thu, 18 Apr 2002 18:42:46 -0400


I am wondering how (of if) you interact with shell commands in
python. For example, in perl you can assign a variable to the
output from a command line. (I am using linux.)

$date = `date`

The string between the backslashes gets passed to the shell.

In python, I see you can use the command

os.system('date')

But can you assign this to a variable? 

Here is another example. I have written a small script in perl to
backup my files. I use perl code to determine what type of backup
I want to do, and store this value in the $backup variable. I
can then pass this to the shell with a command like this. 

`find /bin -ctime -$backup \! -type d`

Perl knows to change the variable $backup to the value stored in
it and then passes it to the shell.

I am hoping you can do this in python. If not, then I can see
where I would be somewhat limited in python.

Thanks!

Paul

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************