Saravana Murthy
Saravana Murthy

Reputation: 553

Running an exe file in python - not working

I have a crazy problem. I have a cmd to run an exe file and it executes with no errors. The cmd in command prompt is

E:\project\cpp\myfirst.exe

I have to call this exe file within my python script. I use subprocess.call. But I get an error. The code and error is as follows

import subprocess
subprocess.call('E:\\project\\cpp\\myfirst.exe')

The error i get is

ERROR: Could not open myfirst setup file
1

I couldnt find the solution. I also tried os.system call. But still the same error. can you guys help me.

NOTE: the exe file is generated from a cpp code

thanks

Upvotes: 1

Views: 1235

Answers (2)

Tim Seed
Tim Seed

Reputation: 5279

Under Linux I have always found the popen mechanism to be more reliable.

from subprocess import Popen, PIPE process = Popen(['swfdump',
'/tmp/filename.swf', '-d'], stdout=PIPE, stderr=PIPE) stdout, stderr =process.communicate()

Answer taken from

How to use subprocess popen Python

Upvotes: -1

bereal
bereal

Reputation: 34272

The program seems to be seeking for some configuration file in the working directory, which is not always the same as the one where the executable is. Try instead:

import subprocess
subprocess.call('myfirst.exe', cwd=r'E:\project\cpp')

If you have written myfirst.exe yourself, consider changing the lookup logic so that it checks the executable's own directory.

Upvotes: 3

Related Questions