ok I had looked on the internet and found one form of running an exe file from a py script, i goes like this.

import os

os.system("c:/windows/iexplore.exe") # Or wherever it lives

Problem is, whenever i run the script with the appropriate path loaded in, i get the following:

Traceback (most recent call last):
  File "C:\csuite\startup.py", line 14, in <modul
    choises(choise)
  File "C:\csuite\startup.py", line 11, in choise
    os.execv("C:\csuite\Re-Codon\rcodon.exe", cho
TypeError: execv() arg 2 must be a tuple or list

I origginally got some kind of error involving a batch or runnable file, so I switched to this because I looked up the os module in python, and apparantly the os.execv will do the job better for me cause it requires a path....

os.execv("C:\csuite\Re-Codon\rcodon.exe")

but when i run the script like that, I get the following...

Traceback (most recent call last):
  File "C:\csuite\startup.py", line 14, in <module>
    choises(choise)
  File "C:\csuite\startup.py", line 11, in choises
    os.execv("C:\csuite\Re-Codon\rcodon.exe")
TypeError: execv() takes exactly 2 arguments (1 given)

I don;t know what those 2 arguments are, how do I find them out?

Here is the python script just incase you need to look at it....

EDIT: The purpose of this little snippet is for a software suite im desging, I made a little program that codes standard alphabet, into the language of DNA, then there's another that goes in reverse. Anyways, I compiled both in py2exe and put the dist folders in one folder called, CSuite. Basically, this script will server as a start screen and when you type 1 or 2, and hit enter, the other one of the two programs will pop up. BTW: Everything is in console form, I plan to make it a UI in the next release.

import os

print "Welcome to the DNA codon encoder, and decoder."
print "Plese select the program you want to use from the list and press enter."
print "If you would like to use the encoder, press 1."
print "If you would like to use the decoder, press 2."
choise = input("So, what program would you like to use?")

def choises(choise):
    if choise == 1:
        os.execv("C:\csuite\Re-Codon\rcodon.exe")
    elif choise == 2:
        os.execv("C:\csuite\Codon\codon.exe")
choises(choise)
Member Avatar for Mouche

So you only got an error with execv? It looks like you need arguments with that. What's wrong with using os.system()?

My ie7 is in "c:/windows/ie7/"

This works on my computer:

import os
os.system("c:/windows/ie7/iexplore.exe")

So you only got an error with execv? It looks like you need arguments with that. What's wrong with using os.system()?

My ie7 is in "c:/windows/ie7/"

This works on my computer:

import os
os.system("c:/windows/ie7/iexplore.exe")

ok that works, but the programs gonna wind up in the program files folder, but when dos reads the script it reads the destination file as C:\Program then it cuts off because of the space...

Member Avatar for Mouche

Well... it seems to be using the older command prompt--the one that doesn't accept spaces.

If you know much about DOS, you might have seen this before:

C:\Progra~1\

Try that.

This seemed to work for me (to open FileZilla in a subdirectory in my Program Files directory):

import os
os.system("C:/Progra~1/FileZilla/FileZilla.exe")

ok cool, it works now, I had forgotten what the whole progra~1 thing, I knoew it existed i just couldnt remember exactly what it was...

Hello,

I found this website while I was trying to search a solution/ recipe for a problem I am trying to tackle... I am very new to python :(

How can I run an executable file from a python script?

for example:

All the files (python script - filename.py-, executable file -filename.exe-, and the file that needs to be processed by the executable file -filename.txt-) are in the same directory - new_folder-.

What do I need to write or include to my script (filename.py) so that it would start filemane.exe would process filename.txt and produce an output file / results?

any help is greatly appreciated!

you can directly email me at

krampuswillgetyou@gmail.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.