1

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

2
  • When you run it from cmd, do you run it from the same directory (i.e. just as myfirst.exe)? Commented Feb 18, 2016 at 11:34
  • Yeah. I run it from the same directory. Commented Feb 18, 2016 at 11:37

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.