How to monitor the MATLAB command window output to automate external script user input only in the event when prompted?

조회 수: 1 (최근 30일)
I wrote a MATLAB function to automate several functions for my office that we perform on a Linux OS. The script fetches simulation logs from various servers, kicks off a Perl script that processes the logs into .mat files and then runs post analysis MATLAB tools on the resulting matfiles.
It's been working great until today when the Perl script hit a corner case and prompted the user for input on permission to rename a file. I'm guessing it was due to some permissions issue on those specific temp files. All the user has to do is hit enter to approve the prompt and because the shell command is executing through MATLAB, the input prompt is in the MATLAB command window. The log processing Perl script is kicked off using MATLAB's system command so as far as I know, "control" hasn't returned to MATLAB until the Perl script completes and it steps to the next line.
I know for typical MATLAB functions that require MATLAB user input, you can pass the function an answer file but is there any way I can have MATLAB dynamically assess what's in its command window from this Perl script shell output to see if this specific prompt appears and automate hitting enter for the user if it appears and do nothing if not?

채택된 답변

Mike
Mike 2022년 8월 24일
편집: Mike 2022년 8월 24일
This wasn't the solution I was hoping for in the context of how I posed the question but I found a workaround for anyone else that runs into this:
Instead of using system('cmd') where cmd is the Perl script call and arguments, use system('yes | cmd'). This automatically provides affirmative answers to proceed through any yes/no prompts. More complex promps and responses can be passed in with files containing 'expect' and 'send' however this is all I needed for my purposes.
Still not sure if MATLAB can monitor its own command window this way but Linux is capable of handling it via the command line so feed that into the system function

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by