[Tutor] os.system

wesley chun wescpy at gmail.com
Sat Dec 18 02:01:50 CET 2010


On Fri, Dec 17, 2010 at 4:17 PM, Emile van Sebille <emile at fenx.com> wrote:
> On 12/17/2010 4:07 PM jtl999 said...
>>
>> I want to pass a variable to os.system which is dir
>>>>> dir=raw_input ("Dir Please ")
>>>>> os.system ("ls"  + dir)
>> sh: ls/: No such file or directory
>
> this has concatenated "ls" and dir
> try with "ls "

in addition to emile's obvious suggestion, i have a few minor ones:

1) don't use a built-in function as a variable name (dir)
2) os.system() only sends off the request. if the cmd has output, you
get it too. you can't capture it like you can with os.popen*()
3) you should consider using subprocess... it obsoletes all the os.*() functions

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list