[Tutor] Problem with os.system
Dave Angel
davea at davea.name
Fri Mar 1 19:00:19 CET 2013
On 03/01/2013 08:07 AM, Vijay Kumar R wrote:
> I was using python for some application which used to create directories and
> also to run some exes using the os.system command from a program.py file
> which was working fine. For some reasons I got my system formatted and got
> the windows 7 installed.
>
>
>
> Now again I installed python and tried running the same program.py. The
> program executes successfully with no errors but my directory and exes are
> not getting invoked.
>
>
>
> I tried creating the below sample program and executed it
>
>
>
> #!/usr/bin/env python
>
> import os
>
> global name_wo_ext
>
> name_wo_ext = "d:\\fun"
>
> os.system("mkdir %s" % (name_wo_ext))
>
>
>
> This gets executed well but there is no directory created
I'm not running Windows, so I can't do the obvious checks.
What kind of drive is your D: partition? For example if it's a CD, you
can't write to it. Likewise, if the root directory is restricted, and
your user doesn't have permissions. cmd.exe doesn't return an error
level, so you don't get much of a clue from there.
Have you tried a different internal command, one that displays
something? Like DIR ?
Have you made sure you have a COMSPEC variable, and that it has a
reasonable velu?
Have you tried a real program? 'mkdir' and 'dir' are internal commands,
built into cmd.exe. Maybe Windows 7 decided to remove it after 30
years. After all, it's just an alias for 'md'
> <snip>
>
>
> Could somebody please help me out in resolving the problem as I have used
> os.system enormously in my program.
os.system has been deprecated at least 8 years, in favor of the
subprocess module. Its flexibility and error handling are quite limited.
>--
DaveA
More information about the Tutor
mailing list