Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing command line arguments

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
Here is a question, I am on win32 using active state perl. Lets say I create a simple perl script called test.pl:
Code:
my($test) = @ARGV;
chomp($test);
print $test;

and I want to pass arguments to the perl script test.pl via a pipe.

Can I do somthing like this????
Code:
 echo HI | test.pl

I get an error when I do this that "The process tried to write to a nonexistent pipe". Can this be done?

Thanks

-T

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Firstly, you're not calling the Perl script correctly (unless it's in your PATH). Also, piping will by default send the output of the "echo" command to Perl's standard input. To use them as arguments, use "xargs", like so:
Code:
echo HI | xargs ./test.pl
 
Here are a couple of code snippets you might like to play with:
Code:
   my @input_args = @ARGV;   # try text and valid filenames
   print "Args: @input_args\n";

   while (<>) {
     chomp;
     print "Piped: $_\n";
   }
and
Code:
   my @input_args = @ARGV;   # try text and valid filenames
   print "Args: @input_args\n";

   while (<STDIN>) {
     chomp;
     print "Piped: $_\n";
   }

I hope that helps.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top