How to use python to start an interactive shell pr

2019-02-25 20:22发布

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!

标签: python shell
1条回答
男人必须洒脱
2楼-- · 2019-02-25 20:33

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")
查看更多
登录 后发表回答