[Tutor] os.system

Steven D'Aprano steve at pearwood.info
Sat Dec 18 02:02:50 CET 2010


jtl999 wrote:
> I want to pass a variable to os.system which is dir
>>>> dir=raw_input ("Dir Please ")
> Dir Please /
> ok dir = /
>>>> os.system ("ls"  + dir)
> sh: ls/: No such file or directory
> 32512
> 
> any advice 

Yes -- learn to read the error messages you get. The error you get is a 
shell error, not a Python error. It is *exactly* the same error you 
would get if you do this by hand:

sh-3.2$ ls/
sh: ls/: No such file or directory

This tells you that the shell can't find a file called "ls/". No 
surprises there -- you want "ls /". So you need to include a space in 
the shell command that you pass to os.system.


-- 
Steven



More information about the Tutor mailing list