[Rt-devel] [patch]: make command-line tool safe to be invoked with IO redirection

Jesse Vincent jesse at bestpractical.com
Mon Aug 25 08:47:40 EDT 2008


On Aug 22, 2008, at 9:27 AM, Otmar Lendl wrote:

>
> Hi,
>
> I was scripting using the command-line "rt" tool and needed to
> do program a sequence like
>
> * rt create -t ticket -e ...
> * rt link ...
> * rt correspond
>
> in a shell (or perl) script.
>
> For the latter two invocations I need the ticket number of the
> newly created ticket, which I can get by redirecting and parsing
> STDOUT of "rt create".
>
> This interferes with the -e option (or the error case) in which
> an editor is called.
>
> I fixed this with:

Depending on /dev/tty feels like it's going to break on some common  
platform or other.  Anyone have any useful guidance?

Best,
Jesse

> --- /usr/bin/rt 2007-10-31 11:52:20.000000000 +0100
> +++ /usr/local/bin/rt 2008-08-20 14:14:20.000000000 +0200
> @@ -1335,7 +1335,7 @@
> local $/ = undef;
>
> open(F, ">$file") || die "$file: $!\n"; print F $text; close(F);
> - system($editor, $file) && die "Couldn't run $editor.\n";
> + system("$editor $file < /dev/tty > /dev/tty") && die "Couldn't run  
> $editor.\n";
> open(F, $file) || die "$file: $!\n"; $text = ; close(F);
> unlink($file);
>
> Any better ideas?
>
> /ol
> -- 
> -=-  Otmar Lendl  --  ol at bofh.priv.at  -=-
> _______________________________________________
> List info: http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel
>



More information about the Rt-devel mailing list