view audio/bash_esc.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents 3cedfd4549ef
children
line wrap: on
line source
% bash_esc - Convert string into escaped version for use in command lines
% bash_esc :: string -> string
function out=bash_esc(in,method)
	import java.io.*;
	if nargin<2, method=1; end

	cs=feature('DefaultCharacterSet');
	runtime=java.lang.Runtime.getRuntime();

	switch method
	case 1 % ALternative 1
		process=runtime.exec({'bash', '-c', 'printf "%q" "$(cat)"'});
		writer=OutputStreamWriter(process.getOutputStream(),cs);
		writer.write(in); writer.close();

	case 2 % ALternative 2
		process=runtime.exec('bash');
		writer=BufferedWriter(OutputStreamWriter(process.getOutputStream(),cs));
		writer.write('printf "%q" "$(cat)"'), writer.newLine();
		writer.write(in); writer.close();
	end

	rdr=BufferedReader(InputStreamReader(process.getInputStream(),cs));
	out=char(rdr.readLine());
	process.destroy();
end