Take the 2-minute tour ×

I've created a named pipe on Debian using mkfifo pipe.in. I want to write to this pipe from Matlab.

To do this, I use the following matlab command:

unix( 'cat <myfile> > pipe.in' )

Where <myfile> is a text file and pipe.in is the pipe I created with mkfifo.

In many cases, the process associated to the pipe crashed for many reason (but any reason beyond the use of the unix and cat command). The crash can be normal in several cases.

Executing the above command causes Matlab to freeze, and I can't regain control with CTRL+C.

Is there another way to release Matlab without requiring me to kill the process?

share|improve this question
Try running the cat command in the background by appending & to the command... –  EitanT Jan 17 '13 at 15:28
How did you create the pipe? –  Rody Oldenhuis Jan 17 '13 at 15:31
@EitanT I try it and it unblocks MatLab but in my case I must wait that the unix command terminates to be sure that the process is completed –  Guuk Jan 17 '13 at 16:08
@RodyOldenhuis I create the pipe as follows: mkfifo pipe.i; mkfifo pipe.out; time echo "<intern command of the executable>"| <executable> > log & –  Guuk Jan 17 '13 at 16:09
What happens if you simply cat the file without the pipe, does this freeze? Have you tried opening the pipe from within matlab using fopen and writing to it using fprintf? –  slayton Jan 17 '13 at 17:22
show 4 more comments

migrated from stackoverflow.com Jan 21 '13 at 4:51

This question came from our site for professional and enthusiast programmers.

1 Answer

Unblocking Matlab

You can unblock Matlab by sending the QUIT signal by pressing CTRL-\ in the terminal that you launched Matlab from.

Why Matlab is freezing

Matlab is freezing because the unix function never returns because cat <myfile> > pipe never terminates.

Executing cat <myfile> > pipe.in in a terminal demonstrates the same "freezing" behavior.

My bash-fu isn't very good, but I think that something must be reading from the pipe before the writer can terminate.

Create a temporary pipe and file

mkfifo /tmp/tempPipe
echo "1 2 3 4 5 6 7 8 0" > /tmp/tempFile

Write to the pipe

This command will not terminate:

cat /tmp/tempFile > /tmp/tempPipe 

This command will:

cat /tmp/tempFile > /tmp/tempPipe & cat < /tmp/tempPipe

I expect that if you create a reading process then your Matlab call to unix will terminate.

share|improve this answer
The freezing "behavior" is not for me a real problem. In the classic case, I would expect that the whole command go through the pipe (because I must wait to do other operations). The freezing behavior is not a problem in a terminal because I can stop it by pressing CTRL+C. But in matlab, I can't use this command. –  Guuk Jan 17 '13 at 20:00
For information, the main process that is managed by the command trough the pipe is a numerical solvor. So, in my case, I have to send commands to the solvor using the pipe (each group of commands leads to a numerical computation). I am waiting that the group of commands go to the pipe and when the last command go to the pipe, I can continue many operations in MatLab before sending new commands. –  Guuk Jan 17 '13 at 20:10
I want just to stop the freezing behavior when the solvor crashs (and the pipe are deleted). –  Guuk Jan 17 '13 at 20:11
@Guuk then use CTRL-\ –  slayton Jan 18 '13 at 1:13
I will try it but in the future I want to use my matlab program on a cluster and I can't use this. Therefore I looked for an automatic so –  Guuk Jan 18 '13 at 6:28
show 1 more comment

Your Answer


