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

Hi There, How to persist variable created in shell script (we do manipulations for some variables in shell script and would like them to be avaibale to perl program even after shell script finished execution)called from Perl after shell script finished execution? Thanks, Sumit
  • Comment on How to persist variable created in shell script called from Perl after shell script finished execution?

Replies are listed 'Best First'.
Re: How to persist variable created in shell script called from Perl after shell script finished execution?
by NetWallah (Canon) on Feb 24, 2014 at 04:14 UTC
    The most common way to get data from a shell command/script is to read the STDOUT from that script, typically using the 'qx' command.

    If STDOUT is already being used for other purposes, you could create and write to a "Named Pipe" using the linux "mkfifo" comman to create, and a standard "echo xxx > pipe/name" to send data, while th perl script reads from the pipe.

    A less efficient way would be to persist data to an actual file on the file system.

            What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
                  -Larry Wall, 1992

Re: How to persist variable created in shell script called from Perl after shell script finished execution?
by Athanasius (Archbishop) on Feb 24, 2014 at 03:36 UTC

    Hello sumitanshutiwari, and welcome to the Monastery!

    One way is to store the shell script’s variable in the local environment, then access it from within Perl via the special %ENV hash. For example (in Windows):

    13:29 >set FOO=bar 13:29 >perl -wE "say $ENV{FOO};" bar 13:30 >

    See perlvar#General-Variables.

    Or, store the shell script variable(s) in a file, and access the file from within Perl in the normal way.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: How to persist variable created in shell script called from Perl after shell script finished execution?
by LanX (Saint) on Feb 24, 2014 at 04:40 UTC
    That's a very general question, the general answer is to dump the variables to a file and to read and eval it in the next run.(see do)

    See Data::Dumper for dumping

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re: How to persist variable created in shell script called from Perl after shell script finished execution?
by LanX (Saint) on Feb 24, 2014 at 04:37 UTC
    Please reap! Sorry update dupe ! :)

    Update: downvoting doesn't help... too many remaining up-votes!

    janitors already messaged.



    a very general question, the general answer is to dump the variables to a file and eval it in the next run.

    See Data::Dumper

    Cheers Rolf

    ( addicted to the Perl Programming Language)