How to read with stdin in matlab

I have a long Matlab script to process data. I want to send him a flag over stdin to say that I have new data to process. I also want to read the flag from stdout when it is processed.

In other words, I have a process A that sends a flag about once per minute to Matlab. I want Matlab to wait until it receives this flag.

Writing to stdout in the matlab process is as simple as calling fprintf. But how can I read from stdin? The documentation fopendoes not mention the input channel as well fread. How to get matlab script to read from stdin?

+4
source share
2 answers

, , input. myscript.m:

str = input('', 's'); 
fprintf(str); 
exit;

:

echo Hello world | matlab -nosplash -nodisplay -nodesktop -r "myscript"

, , "Hello world" Matlab.

, , input stdin, fprintf stdout.

+3

- named pipe. mkfifo MY_PIPE, . - MY_PIPE, . , MY_PIPE, . ./program.sh > MY_PIPE. , Matlab, fopen('MY_PIPE', 'r').

, :

  • Linux .

  • Matlab .

+1

Source: https://habr.com/ru/post/1542079/


All Articles