5.0

5.0 | 1 rating Rate this file 28 downloads (last 30 days) File Size: 112.42 KB File ID: #13851

popen read and write

by Dan Ellis

 

04 Feb 2007 (Updated 05 Feb 2007)

Code covered by the BSD License  

MEX source to acccess popen r/w

Download Now | Watch this File

File Information
Description

popen() -- for "pipe open" -- is a very useful system call provided in many flavors of Unix. It runs a command passed in as a string then returns a file handle so that the parent process can read or write to the process as if it was a file; data passed this way is connected to the standard input or the standard output of the child process.

I created this because I wanted to process very long MP3 files in Matlab. Originally I wrote mp3read to allow me to decode just a small section of a long MP3 file without having to decode the whole thing, but every time I wanted to read another segment, I had to open the file again, then seek through to the point I wanted to read.

Instead, by using popen to open an MP3 decoding process that writes to standard output, I can "pull" as many frames as I want from the file, then put the process to sleep while I deal with those frames, then, on my next read from popen, the process is reawoken and the next block of data can be accessed. But this could be used for any application where there are long data streams to read or write, and you want to handle them a bit at a time.

Two functions are provided, popenr.c for reading from command pipes, and popenw.w for writing to command pipes. Reading and writing to the same command is not supported at present.

MATLAB release MATLAB 7.3 (R2006b)
Other requirements Requires popen() in underlying platform i.e. some kind of Unix (Linux, Mac OS X, ...)
Zip File Content  
Published M Files Popen access from Matlab
Other Files popenmatlab/popenw.c,
popenmatlab/html/popenr_demo.png,
popenmatlab/html/popenr_demo_01.png,
popenmatlab/piano.mp3,
popenmatlab/popenr_demo.m,
popenmatlab/popenr.mexmaci,
popenmatlab/popenr.c
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
07 Apr 2008 Morag Am-Shallem

This is great extension, which providing powerful tool to for interface with other applications.
I've been using two alternatives until now:
1. Output from other apps. to temporary files, and then command 'load ...' from Matlab,
2. Executing them with 'system(...)', which gives output string, then parsing it with 'sscanf(...)'.
Both alternatives waste a lot more time. For my files, 'popenr(...)' is even quicker than loading mat-files with the same data!
Thank you very much.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
data import Dan Ellis 22 Oct 2008 08:59:25
data export Dan Ellis 22 Oct 2008 08:59:25
mex Dan Ellis 22 Oct 2008 08:59:26
unix Dan Ellis 22 Oct 2008 08:59:26
popen Dan Ellis 22 Oct 2008 08:59:26
source Dan Ellis 22 Oct 2008 08:59:26
pipe Dan Ellis 22 Oct 2008 08:59:26
open Dan Ellis 22 Oct 2008 08:59:26
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com