[Tutor] Help with Process Commands

ak@silmarill.org ak@silmarill.org
Mon, 04 Jun 2001 16:04:56 -0400


On Mon, Jun 04, 2001 at 12:48:21PM -0700, Michael Bacayo wrote:
> I want to learn how to use system(), spawnv(), and
> spawnve() the right way. When I use this in a program
> of mine, these commands seem to be inconsistent in the
> manner that the arguments are sent to the called
> program. Sometimes, you need to include the arguments
> in the list or tuple with spaces before and after the
> "'s and sometimes it's not need. The arguments are not
> passed correctly to the called program if not written
> a certain way.
> 
> Thanks!

Here's the os.system() syntax:

os.system('ls -al')

or
os.system('ls -a -l')

IOW, everything inside quotes is passed on to the shell for processing,
so you just use the command the way you'd type it in the shell.

Sometimes you will need to do this:

args = ' -al'
cmd = 'ls'
os.system(cmd + args)

or

args = [' -a',' -l']
cmd = 'ls'
os.system(cmd + args[0] + args[1])



-- 
Shine on you crazy diamond
        - Roger