perlquestion
pileofrogs
<p>Greetings Monks!</p>
<p>Yes, I know I shouldn't have interactive tests. I'll make them all automated or optional or something later. Maybe I'll use expect.</p>
<p>Basically, I'm writing some stuff that will alter user accounts on a system and send them email to tell them what it did. I want the script to run vi so I can review the email and make edits before it gets sent.</p>
<p>In the test harness, vi gets all confused because STDOUT isn't a tty. I can see the text to edit and I can close vi by typing "<esc>:q!" but I can't see the cursor or anything I type. No, this is not a surprise.</p>
<p>I think I need a way to tell the test harness to give me back the TTY for a minute, to stop looking for TAP and then start again.</p>
<p>If I run <c>system("vi $filename")</c> it behaves like I describe. If I run <c>system("vi $filename >&2")</c> it works great (vi still complains, but I don't care.) If I redirect STDOUT to STDERR and back in the test script, it doesn't help. I guess that's what you'd expect because STDOUT is already screwed with before I get there so redirecting it after the fact isn't going to help.</p>
<p>Anyway, is there a good way to handle this? I'm interested not only to solve my problem but also to improve my understanding of all these interacting filehandles and whatnot.</p>
<p>Here's the shortest script I could think of that shows the situation. Obviously you need 'vi' in your path.</p>
<code>
use Test::More;
use File::Temp qw(tempfile);
my $text = 'hi there';
my ($fh,$fname) = tempfile();
print $fh $text;
close($fh);
ok(!system("vi $fname"),'vi exit OK');
open($fh,'<',$fname) || die "Failed to re-open $fname\n";
local $/;
$text = <$fh>;
close($fh);
unlink($fname);
done_testing();
</code>
<p>Thanks All!<br>--Pileofrogs</p>