os.system vs. Py2Exe

Bengt Richter bokr at oz.net
Tue Sep 28 19:43:05 EDT 2004


On 28 Sep 2004 19:15:52 GMT, Grant Edwards <grante at visi.com> wrote:

>On 2004-09-28, Lad <export at hope.cz> wrote:
>
>> Yes, I installed all files( I think) because everything else
>> works. Only os.system does NOT.  I use os.system to open txt
>> file.I use it like os.system('Myfile.txt')
>
>What makes you think that should work?  
>
>Is Myfile.txt an executable file?  Under Win32, don't
>executble file's names usually end in .exe?

It's not a matter of _being_ executable, it's a matter of having an executable
_associated with_ the extension. Typically notepad.exe is associated with .txt
(via an intermediate association with a generic file type name that in turn
is associated with the actual executable):
----
[16:30] C:\pywk\junk>assoc .txt
.txt=txtfile

[16:30] C:\pywk\junk>ftype txtfile
txtfile=C:\WINNT\System32\NOTEPAD.EXE %1
----

>> When I use os.startfile instead  of os.system it works well.
>
>Then why not use os.startfile()?  It's the correct way to start
>the program that is supposed to handle .txt files.
One difference is that os.system will wait for the completion of what it starts,
but os.startfile will start a new process to do it, and return immediately.

I would try it with full absolute paths to everything the in the os.system call.
If that works, you can look for why the environment is different.

BTW, if you execute via start menu or double clicking a desktop icon, the associated
.lnk may specify the starting directory. If that is different from current directory,
bare names may be looked for in unexpected place and not be found (or worse, a file
of the same name may be found, but be the wrong one). Right click on the icon and look
at the properties. Or right click the task bar and chase properties of start menus that way,
or start>settings>taskbar> etc.

BTW2, if you want to type in a file name without extension, as you can with .exe
and .bat etc., it implies a priority choice if e.g. both .exe and .bat exist
in the same path directory. You can influence this by the PATHEXT environment
variable. Go to a console window and type
    help ftype|more
and also
    help assoc|more
for additional info

BTW3, beware of changing .exe association!! I was aghast to find (some time ago) that
NS4.5 let me change that association via its file association option interface.
It was pretty squirrely to get back to normal. No console commands would work.
(IIRC I finally used  start menu>run>browse to find and execute regedit32 and repaired
it that way, after booting in last known good to see what the registry was supposed to be
for .exe). Very anxious moments there ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list