madox has asked for the wisdom of the Perl Monks concerning the following question:

Hello people,

Can someone help me... i'm try to "connect" two Perl script but i can't, see the example:

#
# first.pl
#
#!/usr/bin/perl open HG, '|second.pl'; print HG <<'CMM'; ASDFAS SADF ASDF ASDFSA DF ASD FAS DF ASDF AS DF ASDF AS D FHE WT UWR EUW RTJ SRJ TT H CMM close HG;

And:

#
# second.pl
#
#!/usr/bin/perl open RG, '>./register.txt'; while (<STDIN>) {# i'm test with ARGV,STDIN,ENV and nothing happend print RG; } close RG;

How can i take the input in the second script?

Thank for your help in advance.

Madox

Replies are listed 'Best First'.
Re: Connecting two scripts
by FunkyMonk (Bishop) on Aug 15, 2007 at 10:27 UTC
    If this is intended for a *nix platform, you need to fix up the shebang:

    #!/usr/bin/perl

    You missed the "!".

      Alternatively change the line reading
      open HG, '|second.pl';
      to
      open HG, '|perl second.pl';
      Maybe this would work in windows too (no test environment here).

        No no, both run ok but, can't know how take the input in the second script.

        thk

      Yes, thank for detail, i'm correct this now, but this test laboratory is run on win..

      Thk

        <offtopic>
        ups, it's response the first answer... sorry can't move.
        </offtopic>
Re: Connecting two scripts
by cdarke (Prior) on Aug 15, 2007 at 11:08 UTC
    You should also check the return value for open - if the script could not be found, not in a directory in $PATH for example, then you would not know.
    And:
    use warnings; use strict;

      No no, the first call the second, becouse it's create the file.

      I'm recheck open but can't find the way to read the input in the second script... i don't know what i doing wrong

      thk a lot

Re: Connecting two scripts
by andreas1234567 (Vicar) on Aug 15, 2007 at 11:13 UTC

      Yes, sure, but it's a test laboratory to discover how take input that was sent by other program.

      thk U very much

Re: Connecting two scripts
by ww (Archbishop) on Aug 15, 2007 at 11:49 UTC
    Having second.pl read
    open RG, '>./register.txt';

    from the file you open in first.pl,

    open HG, '|second.pl';
    would help.

    Had you tested your opens, you might have noticed this.

      Sorry, can't understand your idea, you say that the filehandle of the first script exists in the second?, i tried this but not work, anyway, this is a test, in fact and when encounter the way, a non perl program send data to the script

      no, no notice appear

      Thk to all

Re: Connecting two scripts
by madox (Novice) on Aug 15, 2007 at 18:36 UTC

    Thank to all monks!!!

    Finally i'm resolve the problem, te correct way is with STDIN, the problem was becouse i test in windows, but only work on *nix or at least work on *nix

    Only for know, if someone know how to make work it on win machine, post here

    Thank you, all was help

      What you are attempting should work on both. If you post your final code, and the error you are getting on Windows, then we should be able to resolve it.