samer@43: % pipeout - start shell command and return stream for writing to its standard input samer@43: % pipeout :: samer@43: % text ~'bash shell command', samer@43: % bool ~'quiet operation flag' samer@43: % -> java.io.OutputStream ~ 'connected to stdout of command', samer@43: % (void -> action void) ~'call this to clean up afterwards'. samer@43: % samer@43: % If quiet flag is not supplied, it defaults to false. samer@43: function [str,cleanup]=pipeout(cmd,q) samer@43: if nargin<2, q=false; end samer@43: if ~q, fprintf('Starting sub-process: %s\n',cmd); end samer@43: samer@50: cs=feature('DefaultCharacterSet'); samer@43: process=java.lang.Runtime.getRuntime().exec('bash'); samer@43: writer=java.io.OutputStreamWriter(process.getOutputStream(),cs); samer@43: writer.write(cmd); writer.close(); samer@43: samer@0: str=process.getOutputStream(); samer@0: cleanup=@dispose; samer@0: samer@0: function dispose samer@43: if ~q, fprintf('Killing subprocess...\n'); end samer@0: process.destroy(); samer@0: end samer@0: end