in reply to Run Shell script followed by ctrl-c within perl

Harry,
How do you know when to crtl-c the shell script?
And can you change the shell script to finish gracefully instead?
I don't think fork or system will help as they don't give you the PID of the called script, Fork gives you the PID of the child.
You might try something like this;
my $rc = fork; if($rc == 0){ #child system("run_shell_script"); }else{ #parent #decide when to kill shell script by killing child #not sure if this won't create a zombie shell script #and system dosen't return a PID kill 9, $rc; }

Replies are listed 'Best First'.
Re^2: Run Shell script followed by ctrl-c within perl
by harry1982 (Initiate) on Nov 25, 2009 at 06:19 UTC

    My issues is, iam trying to automate a download process , in which iam supposed to call the script which i mentioned

    more information on shell script is as below

    it requires 2 inputs , so when i call this script, i need to the output in screen to key in the inputs

    regarding ctrl-c termination, it will display status at the end as download completed and remains idle, unless we press ctrl-c it wont come out from the script.

    i have no right to modify shell script, so iam thinking alternatives to be considered in perl

    if i fork a child process which can run shell script and upon clicking ctrl-c if child process terminates and returns to parent , it would solve my pupose , but iam not sure if this supports in perl

      If you want to automate the script then you want to steer AWAY from user input/output so you don't want to click anything.
      Look at passing the inputs to your shell script from perl.
      If you have a very interactive shell script you will need to capture the output of the script in perl and have a conversation with it.
      Have a look at backticks in the perl manual or qx//;
      As keszler said IPC::Run seems your best bet for an interactive relationship.