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

2 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Mike
Mike am 24 Aug. 2022
Bearbeitet: Mike am 24 Aug. 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by