1

I'm trying to launch a C++ file using the python function "subprocess". I can begin the execution of the program, but it does not manage to read the data file I put in parameter.

However, when I lauch the C++ file directly with the same path to the same data the program works perfectly.

Do you have any ideas on why it does not work using a subprocess ?

The command line I'm using in my python file looks like this:

datafilePath="/home/*...*/dataFile.txt"

subprocess.run(["./programName", "-f "+datafilePath, (OtherOptionsWorkingFine) ],  cwd="./pathToMyProgram")
    
2
  • 1
    "does not manage" is not a description of the problem. What does it say? Did you try debugging the program? Commented Oct 25, 2021 at 9:06
  • If you print out the argv argument array in your C++ program - one value per line so you can distinguish whitespace within and between arguments - you'll see the difference immediately. Commented Oct 25, 2021 at 9:43

1 Answer 1

4

I think you are adding the datafilePath argument wrongly. Try to add all args as separate list items instead of concatenating (some of) them together as a string.

e.g.

subprocess.run(["./programName", "-f", datafilePath, (OtherOptionsWorkingFine) ],  cwd="./pathToMyProgram")
Sign up to request clarification or add additional context in comments.

1 Comment

Thank that was the problem ! At first it did not work, but that was because I added a space where it was not needed ( I used "-f " instead of "-f")

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.