2

I'm having some trouble running some binaries with subprocess.run

I have a binary file at /tools, lets call the binary program. So I need to call /tools/program.

Every option I try, subprocess shows that the file does not exist. I have tried the following.

ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
TOOL_DIR = ROOT_DIR + '/tools/program'

# All of the following return error not found
program_subprocess = subprocess.run(['./'+TOOL_DIR])
program_subprocess = subprocess.run(['./"'+TOOL_DIR+'"'])
# Tried without the /, cause TOOL_DIR has a slash at the start
program_subprocess = subprocess.run(['.'+TOOL_DIR])

Any idea on how to run binaries with subprocess.run using ./?

EDIT: Also tried

subprocess.run([./\"+TOOL_DIR+'\"'])

5
  • Why do you need the ./? Commented May 11, 2020 at 15:37
  • 2
    It looks like you have an absolute path to the program.... just run /tools/program. The program doesn't seem like its relative to your current working directory so, ./ isn't the right thing to use. Commented May 11, 2020 at 15:38
  • Thats the only way I found how to run the binary im using, at least from the console. Its a go based binary Commented May 11, 2020 at 15:38
  • @tdelaney that was it! I usually check how programs run using cmd before I run the subprocess and the way they go is almost the same. Could you post as answer? Commented May 11, 2020 at 15:42
  • /somewhere/tools/program and ./somewhere/tools/program are completely different paths, and there is a very high chance the latter does not exist. Just use the former without the ., or use only ./tools.program (without the root dir). Commented May 11, 2020 at 15:43

1 Answer 1

3

When running subprocess the operating system has to find the executable file somehow. Normally, executables are installed, can be found in PATH and you just use the program name - subprocess.run(["program"]).

In your case it looks like you know the absolute path to the executable, so you can use it - subprocess.run(["/tools/program"]). The downside is that your script can only be run on machines that have the binary in the /tools directory.

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

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.