#!/usr/bin/perl -w use Fcntl qw(:DEFAULT :flock); use File::Temp qw(tempfile); use File::Spec; my $editor = $ENV{EDITOR} || 'vi'; # for naming temp files, so can chase down which app they are coming # from if problems crop up my ($ourname) = $0 =~ /([\w.-]+)$/; $ourname ||= 'perl'; File::Temp->safe_level(2); my ($tfh, $fname) = tempfile("$ourname.XXXXXXX", DIR => File::Spec->tmpdir, UNLINK => 1); # set autoflush to ensure editor gets the right data my $oldfh = select $tfh; $| = 1; select $oldfh; print $tfh <<"INTRO"; Default text to appear in editor. INTRO # File::Temp locks the file by default, which is not productive # with external editors that also want to lock the file. flock $tfh, LOCK_UN; my $status = system "$editor $fname"; die "external editor failed with $?\n" unless $status == 0; # deal with supplied data seek $tfh, 0, 0 or die "Error seeking on temp file: $!\n"; while (<$tfh>) { print; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Soliciting input via a tempfile passed to an external editor
by Aristotle (Chancellor) on Jan 23, 2003 at 20:14 UTC | |
|
Re: Soliciting input via a tempfile passed to an external editor
by zengargoyle (Deacon) on Jan 24, 2003 at 01:01 UTC | |
by Aristotle (Chancellor) on Jan 24, 2003 at 02:24 UTC |