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

This node falls below the community's minimum standard of quality and will not be displayed.
  • Comment on pass variable to another process when invoking from command line

Replies are listed 'Best First'.
Re: pass variable to another process when invoking from command line
by gaal (Parson) on Dec 27, 2006 at 12:41 UTC
    The two easiest ways to pass information to another process when invoking it is on the command line, and through standard input.

    Say you call the second program from the shell, not the first one. How does it expect the input? It's probably one of these two:

    second_program filename # as a command line option echo "filename" | second_program # piped into its standard input

    When calling second_program, you need to do one of these:

    system "./second_program", $filename and die ... # pass it on the comm +and line # note, system needs +"and" for error checking open my $fh, "| ./second_program" or die ... # via stdin print $fh $filename; # (note, no comma on +this line)
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: pass variable to another process when invoking from command line
by jettero (Monsignor) on Dec 27, 2006 at 12:40 UTC
    bashprompt$ ./program.pl | ./program.pl — nothing could be simpler...

    Course, I went and assumed you meant bash. If you meant open, then you want: open my $out, "|", "./program.pl" or die "lol: $!".

    -Paul

    A reply falls below the community's threshold of quality. You may see it by logging in.