Sending input() from Python API
15 views (last 30 days)
Show older comments
Adam Busch on 12 Jan 2019
Answered: Sean de Wolski on 28 Dec 2021
I am trying to allow for a user to interact with MATLAB scripts from the python console using the matlab engine API for python.
I am currently able to display the output of a script with the following code.
eng = matlab.engine.start_matlab()
prompt("Enter a number: ")
Whenever this runs, the console is frozen with the text
"Enter a number: " and I am unable to interact with the terminal.
I would expect that if the APi uses the python sys.stdout for displaying the output from the scripts that it would also allow for you to use the sys.stdin from the terminal.
Jasmine Dai on 14 Jan 2019
Based on the documentation below:
It seems that user input is not supported by the engine API. I would suggest you provide any user input that you need on the python side and feed them into the engine calls.
sepand soltani on 28 Dec 2021
Can't this confusion be prevented by giving an error to the user when an input functions(input(),keyboard(),..) is called from an engine?
Sean de Wolski on 28 Dec 2021
This works if you start the MATLAB engine with the desktop:
eng = matlab.engine.start_matlab('-desktop')
s = eng.input("Hello World: ", "s")
Find more on Call MATLAB from Python in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!