Odd problem running command-line python scripts (win2k) 
Author Message
 Odd problem running command-line python scripts (win2k)

Here is a test script
--- test_os.py ---
import os
print os.system("DIR > t")

F:\> python test_os.py
0
F:\>

t has the correct listing in it
F:\> del t
F:\> test_os.py
1
F:\>

t doesn't exist

Does anybody have a clue what is going on here?  Apparently, I can't get
any system call to work when the program is not explicitly called by python.

I'm using the default python 2.2.1 installation on windows2000.

Thanks.



Tue, 24 May 2005 00:29:56 GMT  
 Odd problem running command-line python scripts (win2k)
Maybe you have two different Pythons installed; one is found first in the
path, the other has the association for .py files.    I don't know why the
second works differently, though...


Tue, 24 May 2005 01:01:05 GMT  
 Odd problem running command-line python scripts (win2k)

Quote:
> Here is a test script
> --- test_os.py ---
> import os
> print os.system("DIR > t")

> F:\> python test_os.py
> 0
> F:\>

> t has the correct listing in it
> F:\> del t
> F:\> test_os.py
> 1
> F:\>

> t doesn't exist

> Does anybody have a clue what is going on here?  Apparently, I can't get
> any system call to work when the program is not explicitly called by
python.

> I'm using the default python 2.2.1 installation on windows2000.

If you'd said you were running Windows NT I would have suggested this is
traceable to a bug in the Windows command procesor, which apprently won't
redirect the output of commands successfully if the interpreter is divined
from the program's extension rather than being entered directly.

I'm guessing, though. Surely the best advice is "don't do that!"?

Bizarrely, with 2.2.1 build 222 from ActiveState on Windows 2000 Pro I don't
get the error you do, and the file is created whether or not I specify the
interpreter on teh command line.

Time for Windows 2000 Service Pack 2? That's what I'm running.

regards
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Previous .sig file retired to                    www.homeforoldsigs.com
-----------------------------------------------------------------------



Tue, 24 May 2005 01:25:25 GMT  
 Odd problem running command-line python scripts (win2k)
[Brian Kelley wrote]

Quote:
> Here is a test script
> --- test_os.py ---
> import os
> print os.system("DIR > t")

> F:\> python test_os.py
> 0
> F:\>

> t has the correct listing in it
> F:\> del t
> F:\> test_os.py
> 1
> F:\>

> t doesn't exist

> Does anybody have a clue what is going on here?  Apparently, I can't get
> any system call to work when the program is not explicitly called by python.

> I'm using the default python 2.2.1 installation on windows2000.

1. What is the first python.exe on your PATH? This is the Python that is
   being run in the first command.
2. Next, run "regedit" to browse your registry.
   - Open HKEY_CLASSES_ROOT.
   - Go to the ".py" key.
   - What is the "(Default)" value of that key? For me it is
     "Python.File".
   - Go to the "Python.File" (or to the key named in the previous step)
     key off of HKEY_CLASSES_ROOT.  
   - That entry should have a key hierarchy under it that looks like
     this:
        Python.File
            shell
                open
                    command    <--- What is the "(Default)" value here?
     That "(Default)" value is how you second invocation of test_os.py
     is being run. For me this string is:
        C:\Python22\python.exe "%1" %*
     The %1 is replaced with "test_os.py" and %* with any subsequent
     args.

If (1) and (2) result in different Pythons then that may be your
problem.

Trent

--
Trent Mick



Tue, 24 May 2005 01:45:40 GMT  
 Odd problem running command-line python scripts (win2k)

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.

Brian



Tue, 24 May 2005 23:16:18 GMT  
 Odd problem running command-line python scripts (win2k)

Quote:

>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



Wed, 25 May 2005 07:36:26 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. python-mode - running a script that takes command line arguments

2. Run Python script in command line

3. Win2k Command Line - can't start Python

4. how do I run a script with a command line

5. running tcl script from command line

6. trouble running an expect script in cron versus command line

7. How to run TCL Scripts on Open VMS from the DCL Command Line

8. Running an external command from within a Python script

9. RUN command in Win2k

10. CW5.5EE, the Run command and Win2k Pro

11. Win2k command line

12. FW: Problems running Make command for Python 2.2.1 on HP-UX 10.20

 

 
Powered by phpBB® Forum Software