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

Saravana Murthy
  • 543
  • 2
  • 6
  • 16

2 Answers2

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.

bereal
  • 32,519
  • 6
  • 58
  • 104
-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

Community
  • 1
  • 1
Tim Seed
  • 5,119
  • 2
  • 30
  • 26