in reply to Integrating shell cmd to perl script

The shell will start and stop after each call, which i dont want

Why not?

  • Comment on Re: Integrating shell cmd to perl script

Replies are listed 'Best First'.
Re^2: Integrating shell cmd to perl script
by Anonymous Monk on Mar 25, 2015 at 09:14 UTC

    If i call the subroutine (which has the shell cmd), each time from different part of the script, control goes to the subroutine and executes the shell command. The problem here is , when it enters the subroutine and executes the shell cmd it wait take x time to finish the task, which means it is a separate activity. This is what i do not want. Instead, my shell cmd should not have any connections to my other areas/testcases in the script. It should be a complete isolated thread/activity. It should start, execute on its own, finally it should pass the control back, when the script is completed

      Why don't you change the shell script to perform a loop and then use either system( 1, 'shellscript') or my $pid= open( my $fh, 'shellscript |' ) to launch it in the background? You can then kill the shell script when your main program exits.

        Just tried this. I created a separate shell script for snmp polling and called this shell script in the actual perl script as you suggested.

        my $pid= open( my $fh, '<path>/snmp.pl |' );

        But, after executing this am not getting the control back to the perl script. Should i use "&" after snmp.pl?

        Sounds Good. Let me give a try