我正在使用命名管道在一个程序(MATLAB)中捕获另一个程序(wgrib2)的输出。以下是MATLAB代码,system()
函数调用命令行以创建管道:
system('mkfifo myfifo'); % Make a named pipe myfifo
% Call the external program wgrib2 and dump its output to the named pipe myfifo
system('wgrib2.exe multi_1.glo_30m.hs.201212.grb2 -ij 1 165 -ij 1 166 > myfifo &');
fid = fopen('myfifo', 'r'); % Open the named pipe
a = fscanf(fid, '%c'); % Read the output as character
fclose(fid); % Close the "file" (myfifo still exists afterward)
以下是我的问题:
- 在使用完命名管道
myfifo
后,我是否需要关闭它?它似乎会一直存在。 - 如果需要关闭
myfifo
,应该使用什么命令来关闭它? - 我将多次运行上面的代码示例(>1000),因此如果我重复使用这个命名管道并在最后再关闭它,那么是否可以?