view audio/private/pipeout.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents fb17caaf9153
children
line wrap: on
line source
% pipeout - start shell command and return stream for writing to its standard input
% pipeout :: 
%    text ~'bash shell command',
%    bool ~'quiet operation flag'
% -> java.io.OutputStream ~ 'connected to stdout of command',
%    (void -> action void) ~'call this to clean up afterwards'.
%
% If quiet flag is not supplied, it defaults to false.
function [str,cleanup]=pipeout(cmd,q)
	if nargin<2, q=false; end
	if ~q, fprintf('Starting sub-process: %s\n',cmd); end

	cs=feature('DefaultCharacterSet');
	process=java.lang.Runtime.getRuntime().exec('bash');
	writer=java.io.OutputStreamWriter(process.getOutputStream(),cs);
	writer.write(cmd); writer.close();

	str=process.getOutputStream();
	cleanup=@dispose;

	function dispose
		if ~q, fprintf('Killing subprocess...\n'); end
		process.destroy();
	end
end