B
badbob
I'm writing a utility that can get input from a file or from a pipe'd
output from another program:
myprogram -infile test.txt
or
type test.txt | myprogram
So for the above two scenarios, I have:
if ($opt_infile)
{
# read from file
}
else
{
while (<>)
{
#read from stdin
}
}
The problem is, if I just run
myprogram
it sits there waiting for input. What I really want is for it to
detect that nothing is coming in from a PIPE so it should complain
that the program was run incorrectly. I've searched and I've seen
stuff on named pipes and getting output by calling a specific program,
but I need a way to get input from any program.
So what I really want is:
if ($opt_infile)
{
# read from file
}
elsif ( pipe_detected() )
{
while (<>)
{
#read from stdin
}
}
else
{
showUsage();
}
Is this possible? Thanks!
badbob001 (at yahoo period com)
output from another program:
myprogram -infile test.txt
or
type test.txt | myprogram
So for the above two scenarios, I have:
if ($opt_infile)
{
# read from file
}
else
{
while (<>)
{
#read from stdin
}
}
The problem is, if I just run
myprogram
it sits there waiting for input. What I really want is for it to
detect that nothing is coming in from a PIPE so it should complain
that the program was run incorrectly. I've searched and I've seen
stuff on named pipes and getting output by calling a specific program,
but I need a way to get input from any program.
So what I really want is:
if ($opt_infile)
{
# read from file
}
elsif ( pipe_detected() )
{
while (<>)
{
#read from stdin
}
}
else
{
showUsage();
}
Is this possible? Thanks!
badbob001 (at yahoo period com)