Odd problem running command-line python scripts (win2k)

Bengt Richter bokr at oz.net
Fri Dec 6 18:36:26 EST 2002


On Fri, 06 Dec 2002 10:16:18 -0500, Brian Kelley <bkelley at wi.mit.edu> wrote:

>
>As another data point, sys.executable reports that the same version of 
>python is being run by both executions of the script.
>
>As yet another datapoint, on my windows2000 machine at home (no service 
>pack) I get the same behavior except that any system call that runs from 
>an imported module
>
>---some_sys_call.py
>import os
>print os.system("DIR >t")
>
>---caller.py
>import some_sys_call
>
>wheras at work (service pack 5) the system call fails.
>
>So I guess I'll label this as "don't do that" except, isn't typing
>
>some_python_prog.py
>
>at the command line the same as double clicking in explorer?  This 
>troubles me the most. I'll look into it.
>
I would try to get some idea of what the execution environment actually
is at the point where you do os.system. And I would also wonder about
different permissions. At work it may well be more restricted. Are you
using a shortcut to run the program one way or another? If so what do
the shortcut properties say about default directory (and excutable for that matter)?

E.g., compare results various ways of executing wazzup.py below:
(the raw_input will hold the console window which would otherwise
disappear if you double click from explorer)

--< whazzup.py >--------
import os
print os.getcwd()
print os.environ['PATH']
print os.popen('DIR').read()
raw_input('Press Enter to exit ;-)')
------------------------

The popen execution of DIR should show you what the t file content should have been.
If it works both ways, then it would indicate either a redirection problem or a
write permission problem for t, which would have to be trying to write in an unexpected
place, since it worked when run from command line. Double clicking a shortcut with the
wrong default directory specified could do that. If it doesn't work both ways, maybe
somehow DIR is not on the effective path, or it finds another DIR.(exe|bat|cmd)
that you didn't expect.

If that doesn't produce enough clues, let us know.
I'd be surprised if there really was an actual redirection problem
with os.system('DIR > t').

Regards,
Bengt Richter



More information about the Python-list mailing list