1

I have a wrapper file that is reading a JSON file into a dictionary. I am using the os.system("command") command to run a C++ code in this python file. The C++ code takes command line inputs which are key values in the parsed dictionary.

How can i pass a python variable as a command line input for a C++ code using the os.system("command") instruction?

4
  • 2
    could you please show what you have tried so far/any relevant code Commented Apr 24, 2015 at 21:14
  • 2
    You could format the keys and values like e.g. "--key1=value1 --key2=value2 ..." etc. Then append that to the string containing the command. The actual format of the string depends on what the command you want to call can handle of course. Commented Apr 24, 2015 at 21:15
  • Is this about how to pass command line arguments from Python, or is it about how to do the C++ side to receive that information exactly? The only system independent solution to the latter is to use an ASCII encoding such as base 64, and explicitly decode in the C++ program. Commented Apr 24, 2015 at 21:24
  • Hey, I figured!..I just had to typecast the value to string and append..as @JoachimPileborg mentioned. Thanks! Commented Apr 25, 2015 at 21:30

1 Answer 1

1

You can't do that unless you relax one of the restrictions.

Relax the python dict requirement: The command line has a well defined text arguments interface, which can easily handle all the info. You can pass the json filename, the str representation of the dict, or pass name-value pairs as command line arguments.

Relax the system call requirement: Rather than building an executable from the c++ code, you can build a python c++ extension. The c++ code can export functions that take a python dict.

Relax the c++ requirement: Obviously you could code it in python.

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.