3

I have used python subprocess and os module for a while. Now I want to start an interactive C++ program called dumbCalculator from python. This dumbCalculator simply read my input and return its result: when I type 1+2 it returns 3

How can I use my python script to call this dumbCalculator binary? apparently, when dumbCalculator starts, python need to 'give up' its shell.

Any comments?

Thanks a lot!

1

1 Answer 1

4

Either of these two commands will run an interactive program for you and return to Python when the program ends. They will not necessarily return a value from that program. 'bc' is an interactive calculator for testing. It will let you add numbers and then return to Python when you type 'quit'.

>>> os.system("bc")

>>> subprocess.call("bc")
Sign up to request clarification or add additional context in comments.

2 Comments

+1, also check out the python-sh project if it gets any more complex than this.
Links are nice. I think you mean this python-sh, but please correct me if this is the wrong one.

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.