Execute script2 from script1 and transfer two arguments to script2

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rzismanx
    New Member
    • Oct 2008
    • 5

    Execute script2 from script1 and transfer two arguments to script2

    Hello everybody

    need help:
    How do i execute script2 from script1 and transfer two things
    $first and $second from script1 to script2
    Need to do it in unix enviroment and windows also(cmd).

    There is a command :system()
    i used it as follows:
    Code:
    #script1;
    system ("/just/an/example/script2 $first  $second  ");
    Did not see any response to this command,
    Please help
    Thanks a lot
  • Arepi
    New Member
    • Sep 2008
    • 62

    #2
    Try them:

    Code:
     open(PIPE,"|perl -w script2.pl"); 
     print PIPE "$omething";
     close(PIPE);
    if so in script2 must wait for data <>;

    when use pipeing from shell, the output of script1 is the input of script2.

    Code:
    perl script1.pl | perl script2.pl
    Last edited by Arepi; Nov 4 '08, 09:50 PM. Reason: code

    Comment

    • rzismanx
      New Member
      • Oct 2008
      • 5

      #3
      Hello again


      The problem with what you suggested is that script1
      does a lot of things and among those things it is printing out
      some results.So how exectly can i extract that certain data that is needed for script2 from script1.
      furthermore i need to transfer two arguments.
      Isn't <> waits for one variable?

      Thanks again

      Comment

      • nithinpes
        Recognized Expert Contributor
        • Dec 2007
        • 410

        #4
        If I understood your requirement correctly, all you want to do is to execute script2 from script1 and pass arguments to script2 from script1.
        If that is so, you have to handle these arguments(@ARGV ) properly in script2. For example,
        script1.pl
        Code:
        #script1
        $first = "Hi";
        $second= "Hello";
        system ("D:\\script2.pl $first $second ");
        and
        script2.pl
        Code:
        #script2
        my ($one,$two) = @ARGV; 
        print "first: $one\n";
        print "second: $two\n";
        would print:
        Code:
        first: Hi
        second: Hello

        Comment

        • rzismanx
          New Member
          • Oct 2008
          • 5

          #5
          I'm just stupid

          Thanks for the reply.

          At the begining it did not worked becuase i forgot somthing:
          Code:
          (system ("[U]perl[/U] /path/sc2.pl $first $second ")== 0) or die "myprogram failed ($?): $!";
          I forgot the "perl" at the command, that why it could not execute the second script.
          Stupid, isn't it

          Thanks a lot

          Comment

          Working...