I have tried it and it works:
----------------------------------------------cut here----------
#!/local/bin/perl
$allowed = "(imaker|cal|ls)$"; # only programs that match this regex are allowed to run
$file = shift || &usage;
open(F, "$file") || die;
$cmd = <F>;
chop($cmd);
#print "<$cmd>\n"; exit;
@ARGV = split(/ /, $cmd);
if ($ARGV[0] =~ /^-/) {
$how = shift;
grep($_ eq $how, "-html", "-text", "-xterm", "-null") || &usage;
};
$how = "-html" unless defined $how;
die "Not allowed to run this program \"$ARGV[0]\""
unless $ARGV[0] =~ /$allowed/;
if ($how eq "-text" || $how eq "-html")
{
open(PIDFILE, "$ENV{'HOME'}/.mosaicpid") || die "No mosaic is running";
$pid = <PIDFILE>;
close(PIDFILE);
$tmpfile = "/tmp/out-$$";
$tmpfile .= ".txt" if $how eq "-text";
$tmpfile .= ".html" if $how eq "-html";
open(STDOUT, ">$tmpfile");
}
if ($how eq "-null")
{
open(STDOUT, ">/dev/null");
open(STDERR, ">/dev/null");
}
if ($how eq "-xterm")
{
@xterm = ("xterm", "-e");
}
open(STDIN, "/dev/null");
system @xterm,@ARGV;
if ($how eq "-text" || $how eq "-html")
{
open(CONTROL,"> /tmp/Mosaic.$pid");
print CONTROL "goto\n";
print CONTROL "file://localhost$tmpfile\n";
close(CONTROL);
kill "USR1",$pid;
system "(sleep 5; rm -f $tmpfile)&"
}
sub usage
{
die "Usage: mosaic-run [-text|-html|-xterm|-null] command args...\n";
}