queuing up user input via writes to STDIN
- From: gavin.bowlby@xxxxxxxxxx (Gavin Bowlby)
- Date: Thu, 27 Jul 2006 20:45:34 -0700
All:
I have a program that reads STDIN for user commands while the program is
running.
I'm adding the capability to queue up user commands from the shell
command line when the program is invoked.
I'd like to be able to queue the command line data up in STDIN, so that
when the program goes into a loop reading STDIN, it will see the command
line data that was queued up as if it came from the command line.
Here's an example:
========================================================================
===
#!/usr/bin/perl
use strict;
use warnings;
my $kbcmd;
#close STDIN;
#open(STDIN, ">"); <== doesn't work so swell
foreach (@ARGV) {
print "input parameter:$_\n";
# print STDIN "$_\n";
# this fails with " Filehandle STDIN opened only for input", see
below
}
#close STDIN;
#open(STDIN, "<");
# and here's a loop that reads STDIN for user commands
while(1) {
$kbcmd = <STDIN>;
print "keyboard command received: $kbcmd";
}
$ perl -d test3.pl a b c
Loading DB routines from perl5db.pl version 1.28
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(test3.pl:8): my $kbcmd;
DB<1> s
main::(test3.pl:10): foreach (@ARGV) {
DB<1>
main::(test3.pl:11): print "input parameter:$_\n";
DB<1>
input parameter:a
main::(test3.pl:12): print STDIN "$_\n";
DB<1> s
Filehandle STDIN opened only for input at test3.pl line 12.
at test3.pl line 12
========================================================================
====
Of course, there are lots of other ways to do this, like saving the
commands in an array and executing the array elements as if they were
keyboard commands, or opening a pipe to another program that fed
commands in.
Is there a way to do this with manipulation of STDIN?
thanks,
Gavin Bowlby
.
- Follow-Ups:
- Re: queuing up user input via writes to STDIN
- From: Michael Gale
- Re: queuing up user input via writes to STDIN
- From: John W. Krahn
- Re: queuing up user input via writes to STDIN
- Prev by Date: RE: Dynamically choosing CGI file based on form output
- Next by Date: Re: queuing up user input via writes to STDIN
- Previous by thread: File opeartions help
- Next by thread: Re: queuing up user input via writes to STDIN
- Index(es):
Relevant Pages
|