473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

os.system vs. Py2Exe

Lad
I used Py2exe to compile my script( I use XP).
The compiled script works OK on my XP where Python is installed.
But when I install the compiled exe to another computer,

os.system

causes the following error:
Bad file or command name

Any help would be appreciated.
Lad
Jul 18 '05 #1
19 2190
Am Tue, 28 Sep 2004 03:00:23 -0700 schrieb Lad:
I used Py2exe to compile my script( I use XP).
The compiled script works OK on my XP where Python is installed.
But when I install the compiled exe to another computer,

os.system

causes the following error:
Bad file or command name


Hi,

What do you execute with os.system?

If the script you execute startswith
#!INTERPRETER
you might have trouble. I don't think this
is well supported under windows.

Try this: os.system("INTERPRETER SCRIPT")
Regards,
Thomas

Jul 18 '05 #2
ex****@hope.cz (Lad) wrote in message news:<81*************************@posting.google.c om>...
I used Py2exe to compile my script( I use XP).
The compiled script works OK on my XP where Python is installed.
But when I install the compiled exe to another computer,

os.system

causes the following error:
Bad file or command name

Any help would be appreciated.
Lad


Did you install the python dll as well?
Jul 18 '05 #3
Lad
gj*****@usa.com (Greg) wrote in message news:<77**************************@posting.google. com>...
ex****@hope.cz (Lad) wrote in message news:<81*************************@posting.google.c om>...
I used Py2exe to compile my script( I use XP).
The compiled script works OK on my XP where Python is installed.
But when I install the compiled exe to another computer,

os.system

causes the following error:
Bad file or command name

Any help would be appreciated.
Lad


Did you install the python dll as well?


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')

When I use os.startfile instead of os.system it works well.
Jul 18 '05 #4
On 2004-09-28, Lad <ex****@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?
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.

--
Grant Edwards grante Yow! Are we live or
at on tape?
visi.com
Jul 18 '05 #5
Lad wrote:
I used Py2exe to compile my script( I use XP).
The compiled script works OK on my XP where Python is installed.
But when I install the compiled exe to another computer,


What operating system is the other computer running?
Jul 18 '05 #6
Lad wrote:
gj*****@usa.com (Greg) wrote in message news:<77**************************@posting.google. com>...

ex****@hope.cz (Lad) wrote in message news:<81*************************@posting.google.c om>...

I used Py2exe to compile my script( I use XP).
The compiled script works OK on my XP where Python is installed.
But when I install the compiled exe to another computer,

os.system

causes the following error:
Bad file or command name

Any help would be appreciated.
Lad

Did you install the python dll as well?


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')

When I use os.startfile instead of os.system it works well.


I suspect that the situation here is that you've got some unusual WinXP
setting that's telling it that .txt files are executable in some way.
If os.system('file.txt') works on your system, then it's your system
that's the odd one; Python (and the other computer) are behaving as
expected. (It's possible, in Win2K/WinXP, to register particular
extensions as 'executable' through a specific other program; this is how
..py scripts are handled, so typing 'script.py' is equivalent to typing
'python script.py'.)

Remember, os.system() is roughly equivalent to typing the argument at a
command line. Does typing "myfile.txt" at a commandline prompt open
that file in a text editor? (Hint -- it shouldn't, under normal
circumstances.)

In this case, I'm pretty sure that using os.startfile() is the
appropriate way of doing what you want.

Jeff Shannon
Technician/Programmer
Credit International

Jul 18 '05 #7
Jeff Shannon wrote:
I suspect that the situation here is that you've got some unusual WinXP
setting that's telling it that .txt files are executable in some way.
If os.system('file.txt') works on your system, then it's your system
that's the odd one; Python (and the other computer) are behaving as
expected. (It's possible, in Win2K/WinXP, to register particular
extensions as 'executable' through a specific other program; this is how
.py scripts are handled, so typing 'script.py' is equivalent to typing
'python script.py'.)

Remember, os.system() is roughly equivalent to typing the argument at a
command line. Does typing "myfile.txt" at a commandline prompt open
that file in a text editor? (Hint -- it shouldn't, under normal
circumstances.)


Unfortunately for your theory, on XP typing just the name of the
file (at least with a .txt file) does indeed open it in the associated
application.

I suspect the "other" machine he is using is not an XP machine, and
thus not suffering from such unexpected behaviour. Thanks, Mickysoft...

-Peter
Jul 18 '05 #8
Peter Hansen wrote:
Jeff Shannon wrote:
Remember, os.system() is roughly equivalent to typing the argument at
a command line. Does typing "myfile.txt" at a commandline prompt
open that file in a text editor? (Hint -- it shouldn't, under normal
circumstances.)

Unfortunately for your theory, on XP typing just the name of the
file (at least with a .txt file) does indeed open it in the associated
application.

Why, so it does... and under Win2K, as well.
I suspect the "other" machine he is using is not an XP machine, and
thus not suffering from such unexpected behaviour. Thanks, Mickysoft...

Yes, if the "other" machine is Win9x/ME (or, I believe, NT4), using the
..txt filename as a command will result in an error. As it should, also,
under *nix (and probably MacOS) as well, unless I'm even more confused
than I'd thought. ;)

This does, at least, do away with the need to presume some sort of
screwy settings on the O.P.'s machine -- said screwy settings being
provided by default from Microsoft. ;)

Jeff Shannon
Technician/Programmer
Credit International

Jul 18 '05 #9
On 28 Sep 2004 19:15:52 GMT, Grant Edwards <gr****@visi.com> wrote:
On 2004-09-28, Lad <ex****@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
Jul 18 '05 #10
Lad
Peter Hansen <pe***@engcorp.com> wrote in message news:<Rd********************@powergate.ca>...
Lad wrote:
I used Py2exe to compile my script( I use XP).
The compiled script works OK on my XP where Python is installed.
But when I install the compiled exe to another computer,


What operating system is the other computer running?


The other Operating system( that does not work with os.system) is Windows 98
Jul 18 '05 #11
Lad
bo**@oz.net (Bengt Richter) wrote in message news:<cj*************************@theriver.com>...
On 28 Sep 2004 19:15:52 GMT, Grant Edwards <gr****@visi.com> wrote:
On 2004-09-28, Lad <ex****@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


..txt file is associated with a propper application( Notepad.txt). AS I
said above, with os.startfile the file is open in Notepad.txt but not
if I use os.system. I can not use os.startfile, because it does not
wait until .txt file is closed
Jul 18 '05 #12
Lad wrote:
Peter Hansen <pe***@engcorp.com> wrote in message news:<Rd********************@powergate.ca>...
Lad wrote:
I used Py2exe to compile my script( I use XP).
The compiled script works OK on my XP where Python is installed.
But when I install the compiled exe to another computer,


What operating system is the other computer running?


The other Operating system( that does not work with os.system) is Windows 98


That's the source of your problem. Win98 doesn't work the way
XP/NT does, and you *cannot* use os.system() in this way to
get the expected behaviour. Find another approach... maybe
read the registry entries for .TXT files and launch NotePad
directly...

-Peter
Jul 18 '05 #13
Lad
Peter L Hansen <pe***@engcorp.com> wrote in message news:<4_********************@powergate.ca>...
Lad wrote:
Peter Hansen <pe***@engcorp.com> wrote in message news:<Rd********************@powergate.ca>...
Lad wrote:

I used Py2exe to compile my script( I use XP).
The compiled script works OK on my XP where Python is installed.
But when I install the compiled exe to another computer,

What operating system is the other computer running?


The other Operating system( that does not work with os.system) is Windows 98


That's the source of your problem. Win98 doesn't work the way
XP/NT does, and you *cannot* use os.system() in this way to
get the expected behaviour. Find another approach... maybe
read the registry entries for .TXT files and launch NotePad
directly...

I found out the following:
on Xp I can use
os.system('IDPass.txt')

but on Win98
it does not work.
So I must use
os.system('notepad.exe IDPass.txt') to open IDPass.txt file
but the problem with Win 98 is the following:
Notepad is launched but the Python running program ( exe compiled
script) is not paused( until I close the Notepad window) but continues
running with the next command.In other words Notepad runs
independently on my exe program.
WHY?

Lad
if verseOS[3]==2:#XP
os.system('IDPass.txt')
if verseOS[3]==1:#Windows 95/98/ME
print "Windows 95/98/ME running"
os.system('notepad.exe IDPass.txt')
Jul 18 '05 #14
On 28 Sep 2004 23:46:34 -0700, ex****@hope.cz (Lad) wrote:
[...]
.txt file is associated with a propper application( Notepad.txt). AS I
said above, with os.startfile the file is open in Notepad.txt but not
if I use os.system. I can not use os.startfile, because it does not
wait until .txt file is closed

Just curious, what happened when you tried specifying the full absolute path to your
..txt file when calling os.system? e.g.
filename = 'something.txt' # for example
os.system(os.path.abspath(filename))
?

Regards,
Bengt Richter
Jul 18 '05 #15
ex****@hope.cz (Lad) wrote in message news:<81*************************@posting.google.c om>...
Peter L Hansen <pe***@engcorp.com> wrote in message news:<4_********************@powergate.ca>...
Lad wrote:
Peter Hansen <pe***@engcorp.com> wrote in message news:<Rd********************@powergate.ca>...

>Lad wrote:
>
>>I used Py2exe to compile my script( I use XP).
>>The compiled script works OK on my XP where Python is installed.
>>But when I install the compiled exe to another computer,
>
>What operating system is the other computer running?

The other Operating system( that does not work with os.system) is Windows 98


That's the source of your problem. Win98 doesn't work the way
XP/NT does, and you *cannot* use os.system() in this way to
get the expected behaviour. Find another approach... maybe
read the registry entries for .TXT files and launch NotePad
directly...

I found out the following:
on Xp I can use
os.system('IDPass.txt')

but on Win98
it does not work.
So I must use
os.system('notepad.exe IDPass.txt') to open IDPass.txt file
but the problem with Win 98 is the following:
Notepad is launched but the Python running program ( exe compiled
script) is not paused( until I close the Notepad window) but continues
running with the next command.In other words Notepad runs
independently on my exe program.
WHY?

Lad
if verseOS[3]==2:#XP
os.system('IDPass.txt')
if verseOS[3]==1:#Windows 95/98/ME
print "Windows 95/98/ME running"
os.system('notepad.exe IDPass.txt')


You can use this instead of os.system()

import os
fh=os.popen("notepade myfile.txt")
fh.close()
(but you should add the appropriate exception handling)

This opens notepad and python will exit if you ran it like this
python myscript.py myfile.txt

If you ran python interactively, then you are returned to the python
command line, after the os.popen() statement. In which case you should
manually close the file, as shown above.

fh is a file object, so if you want to you can read from that object.

This should work on W98, Win2K, Win XP and does not depend on any file
associations.

I would not use os.startfile() for anything, if you are expecting to
open a specific application that is associated with a file extension,
because many applications re-associate file extensions during
installation. Additionally, The user may have intentionally
re-associated .TXT with a different program, because notepad is so
lame.

There are many variations of popen(), but popen() is probably the
simplest for your situation.
Jul 18 '05 #16
Lad
> You can use this instead of os.system()

import os
fh=os.popen("notepad myfile.txt")
fh.close()
(but you should add the appropriate exception handling)

This opens notepad and python will exit if you ran it like this
python myscript.py myfile.txt

If you ran python interactively, then you are returned to the python
command line, after the os.popen() statement. In which case you should
manually close the file, as shown above.

fh is a file object, so if you want to you can read from that object.

This should work on W98, Win2K, Win XP and does not depend on any file
associations.

I would not use os.startfile() for anything, if you are expecting to
open a specific application that is associated with a file extension,
because many applications re-associate file extensions during
installation. Additionally, The user may have intentionally
re-associated .TXT with a different program, because notepad is so
lame.

There are many variations of popen(), but popen() is probably the
simplest for your situation.


Thanks a lot for your help.
os.popen can open file on both Xp and Win98. But there is still a
problem.
When I open myfile.txt (on Win98) by
os.popen("notepad myfile.txt")
my Python program continues running but I would need it to wait until
notepad
window ( with myfile.txt) is closed.
On XP platform the python program execution is paused until I close
the Notepad window.The same I need on Win98 platform
Thanks for help.
LAd
Jul 18 '05 #17
Lad wrote:
You can use this instead of os.system()

import os
fh=os.popen("notepad myfile.txt")
fh.close()
(but you should add the appropriate exception handling)

This opens notepad and python will exit if you ran it like this
python myscript.py myfile.txt

If you ran python interactively, then you are returned to the python
command line, after the os.popen() statement. In which case you should
manually close the file, as shown above.

fh is a file object, so if you want to you can read from that object.

This should work on W98, Win2K, Win XP and does not depend on any file
associations.

I would not use os.startfile() for anything, if you are expecting to
open a specific application that is associated with a file extension,
because many applications re-associate file extensions during
installation. Additionally, The user may have intentionally
re-associated .TXT with a different program, because notepad is so
lame.

There are many variations of popen(), but popen() is probably the
simplest for your situation.

Thanks a lot for your help.
os.popen can open file on both Xp and Win98. But there is still a
problem.
When I open myfile.txt (on Win98) by
os.popen("notepad myfile.txt")
my Python program continues running but I would need it to wait until
notepad
window ( with myfile.txt) is closed.
On XP platform the python program execution is paused until I close
the Notepad window.The same I need on Win98 platform
Thanks for help.
LAd

Try with other version of popen such as popen2, popen3, popen4. I find
useful popen3, that pause my script.
os.popen3(...)

bye
Astyonax
Jul 18 '05 #18
Lad wrote:
I used Py2exe to compile my script( I use XP).
The compiled script works OK on my XP where Python is installed.
But when I install the compiled exe to another computer,

os.system

causes the following error:
Bad file or command name

Any help would be appreciated.
Lad

Check if
os.system('start /wait File.txt')
is working under Win9x.
It's for sure will work under WinNT+

--
Best regards,
Michael Dubner (dubnerm.at.mindless.com)
Jul 18 '05 #19
Lad
"Michael P. Dubner" <du**********@mail.ru> wrote in message news:<ma**************************************@pyt hon.org>...
Lad wrote:
I used Py2exe to compile my script( I use XP).
The compiled script works OK on my XP where Python is installed.
But when I install the compiled exe to another computer,

os.system

causes the following error:
Bad file or command name

Any help would be appreciated.
Lad

Check if
os.system('start /wait File.txt')
is working under Win9x.
It's for sure will work under WinNT+


os.system('start /wait File.txt') WORKS!! Thanks a lot
Lad
Jul 18 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: bap | last post by:
When I try to run a program on a clean machine using the VPython extensions after compiling with PY2EXE I get the following error message: "The procedure entry point IsWow64Process could not be...
0
by: David Vaughan | last post by:
py2exe and Pmw problem ---------------------- I was really surprised not to find some faq setting out what to do to get py2exe working for a program using Pmw. I'm haemorrhaging time here, and...
0
by: Jimmy Retzlaff | last post by:
py2exe 0.6.4 released ===================== py2exe is a Python distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python...
0
by: Jimmy Retzlaff | last post by:
py2exe 0.6.5 released ===================== py2exe is a Python distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python...
2
by: Maria.Reinhammar | last post by:
I have an app using active_directory.py and the std module asyncore in a Windows Service. Works perfectly! That is, until I try to use py2exe to create a standalone (need to avoid installing the...
0
by: Jimmy Retzlaff | last post by:
py2exe 0.6.6 released ===================== py2exe is a Python distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python...
5
by: Michael | last post by:
I'm trying to build a exe on a vista system using py2exe. It will deploy to vista and XP systems. If it matters, the application uses pyserial, as well. I have VS Studio 2005 installed on this...
1
by: Jimmy Retzlaff | last post by:
py2exe 0.6.8 released ===================== py2exe is a Python distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python...
0
by: Larry Bates | last post by:
Jimmy Retzlaff wrote: Everyone, Thanks for all your hard work on py2exe, it is greatly appreciated. -Larry Bates
0
by: Jimmy Retzlaff | last post by:
py2exe 0.6.9 released ===================== py2exe is a Python distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.