Current drive and directory
Diez B. Roggisch
deetsNOSPAM at web.de
Wed May 26 18:07:33 EDT 2004
EAS wrote:
> Howcome when I run this script:
>
> print """MS-DOS Prompt
> 'Q' to Quit"""
>
> import os
> command = ""
>
> while command.lower() != "q":
> directory = os.getcwd()
> print "\n", directory, "\b>",
> command = raw_input("\b")
> os.system(command)
>
> it doesn't update the directory when I use 'cd' for the command prompt?
I'm no windows user, but under unix a child process (which is created using
os.system) inherits the environment of its porent process as a copy - so
chtanges in the childs env don't affecth the parents one. Which is
probablpy a good idea, as ontherwise I'd be able to manipulate the calling
process in undesirable ways.
So I think you need some parsing to intercept a cd and change your current
working dir using the os module.
Aren't there more shell like interactive pythons out there - ipython or so?
Look at them, they might be what you seem to be after here.
--
Regards,
Diez B. Roggisch
More information about the Python-list
mailing list