G'day all,
I wrote this script, called hr for now.
The idea behind this script is to add infinite preprocessing abilities to programs which have none. For example, I might have a script for parsing some source file into html code, and I want to view that in mozilla. Rather than
Code:
$ script_to_parse_into_html < source_file > /tmp/temp.html; mozilla /tmp/temp.html
I can use hr!
Code:
$ mozilla `hr 'script_to_parse_into_html < source_file'`
This might seem stupid, but for me, it means less typing each time. Plus, I don't have to be creative thinking of a temporary file that doesn't already exist each time.
This is a
Request For Comments. Do you think this concept is stupid? Do you like it? How could the perl script be improved?
http://soundless-screams.net/pcwd/misc/hr
Code:
#!/usr/bin/perl -w
# This script passes its arguments to a shell, saving
# the output to a temporary file. This script then
# prints the name of that temporary file to stdout.
# Make temp directory if not already there.
my $tmpdir = '/tmp/hr';
if (!(-d $tmpdir)) {
mkdir $tmpdir;
}
my $outfile = `mktemp $tmpdir/.XXXXXX`;
my $ret;
if (!($ret = system(join(' ', @ARGV, " > $outfile")))) {
print $outfile;
} else {
print STDERR "hr: Error running given command! $ret";
exit 1;
}
exit 0;