in reply to passing values to another perl program

If you want to gather another program's output, use the built-in backticks:

my $output = `ldbtest.pl -e aa100001 -t 123`;

But be *VERY CAREFUL* and run under taint mode if the use r is going to be allowed to pass parameters to the other script.

HTH perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); $rose = "smells sweet to degree $n"; *other_name = *rose; print "$other_name\n"' </code>

Replies are listed 'Best First'.
Re: Re: passing values to another perl program
by treebeard (Acolyte) on Jul 09, 2001 at 20:44 UTC

    I used the line from above and the line that returned to me is...

    sh: -t: not found

    below are the two programs, stripped down, that I am trying to run. The first one calls the second, which should print out the values. At this point all that I am trying to accomplish is seeing that the values get over.

    Here are the two programs: #!/use/bin/perl -w open(EXT,"< LDB_EXTID.lst") || die "something"; while (<EXT>) { push (@externaluids, $_) || die "dead again"; } close (EXT) foreach $externaluid (@externaluids) { my $output = `ldbtest.pl -e $externaluid -t 123`; #for my testing purposes $counter++; exit if $counter > 10; } exit #program ldbtest is simply... #!/use/bin/perl -w use Getopt::Std; getopt ('et'); print $opt_e print $opt_t exit

      Lemme reiterate Malkavian's suggestion in Re: passing values to another perl program; as we can now tell from your posted code, you're snagging individual lines from the one file, and interpolating those values into your backticks; but as he suggested might be the problem, you've got newlines in there and so the -t is seen as the beginning of a new command. Here's one way to rewrite your code:

      open (EXT, "LDB_EXTID.lst") or die "something"; my @uids = <EXT>; # read in each line as a member of the array close EXT; # here's the key line ! chomp @uids; # remove any trailing newlines from every member of @uids foreach my $uid (@uids) { my $output = `ldbtest.pl -e $uid -t 123`; last if ++$counter > 10; } # stuff you'd do after the loop, if anything

      perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
Re^2: passing values to another perl program
by Athahar (Initiate) on Apr 06, 2006 at 07:26 UTC
    Hi, I have a scenario, which I’m working on.. Perl script 1 abc.pl--- will have two parameters, $paramter1 $paramter2 It will call another perl script 2—xyz.pl, passing the two parameters, The perl script2, will be a tcp client requesting for a service with a java server. Once the service is done, I need to return a success/error code of 0 or 1 to th main perl script abc.pl Could u please explain how to do it.. I’m a newbie.. (abc.pl) #!/usr/local/bin/perl # # composite series of images over a background image # print "\nThis is from abc.pl"; $path = "/usr/bin"; $hostName ="127.0.0.1"; $cmd = "perl xyz..pl $hostName $path"; system($cmd)== 0 or die "system $cmd failed: " ,$? >> 8; if ($? == -1) { print "\n failed to execute: $!\n"; } elsif ($? & 127) { printf "\n child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without'; } else { printf "\nchild exited with value %d\n", $? >> 8 ; } And I need to write xyz.pl I’m able to get param from abc.pl, But how to send back the error/ success code #!/usr/local/bin/perl # # composite series of images over a background image # use IO::Socket::INET; print "\n This is in xyz.pl"; if ($#ARGV != 1) { print "usage: e2.pl hostname , pathofResults \n"; exit(2); } $hostName = $ARGV[0]; $path = $ARGV1; #is this possible??? $msg = $hostName+$path ; # Create a new socket $MySocket=new IO::Socket::INET->new(PeerPort=>5000,Proto=>'tcp',PeerAddr=>’127.0.0.1’); # Send messages to server $MySocket->send($msg); $MySocket->recv($text,1024); print "\nReceived message : ", $text,"\n"; exit (2);