: make command-line tool safe to be invoked with IO redirection

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:

— /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@bofh.priv.at -=-

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

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

The only other option I see is to add a command-line option to give a
filename into which the response from the server gets written.
That doesn’t win an prize for elegance, though.

Another question for the command-line tool:

If the server returns an error, the user is dumped into the editor.
What is the user supposed to do if he wants to abort the operation?
Clear the file? ^C doesn’t work as that affects the editor and not
the script.

/ol
-=- Otmar Lendl – ol@bofh.priv.at -=-

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

I also have the feeling that this is a bad way to do it, but my
brain’s in vacation mode and I can’t think of the precise reason why
at the moment.

Tim

The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.

Sorry, I didn’t reply all previously, but I believe I had rt working
on Windows before. Depending on /dev/tty would not work there at all.

Steve Peters
steve@fisharerojo.orgOn Tue, Aug 26, 2008 at 7:06 AM, Tim Cutts tjrc@sanger.ac.uk wrote:

On 25 Aug 2008, at 8:47 am, Jesse Vincent wrote:

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

I also have the feeling that this is a bad way to do it, but my
brain’s in vacation mode and I can’t think of the precise reason why
at the moment.

Tim


The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.


List info: http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel

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

The only other option I see is to add a command-line option to give a
filename into which the response from the server gets written.
That doesn’t win an prize for elegance, though.

Another question for the command-line tool:

If the server returns an error, the user is dumped into the editor.
What is the user supposed to do if he wants to abort the operation?
Clear the file? ^C doesn’t work as that affects the editor and not
the script.

That certainly sounds like it could use improvement. I think I’ve
always “quit the editor and hit control C”

But really, the editor-running bit should be able to sense if you
haven’t changed the file.

I’d love a patch. Possibly something which optionally uses
Proc::InvokeEditor if it’s installed or cargo-cults the logic from lib/
SVK/Util.pm (in the svk codebase, which happens to be something I have
with me on the plane :wink: