http://qs1969.pair.com?node_id=678941

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

Morning monks.

This is a question about running a shell script from a Perl script, and then making the shell script wait and accept input from the perl script. I can only submit jobs to our queueing system via a shell script, but I want to do other stuff (involving e.g. Tie::File) that would be a real pain to re-write in a shell script. Recalling the shell script every time a job is generated and passing it the data from the Perl script is not an option, neither is waiting until all the jobs are generated and passing them en masse. It needs to start up, and then accept input as and when it's generated from the Perl script. The shell script basically does (pseudo code):

Configure the grid engine to receive a batch of jobs foreach job @jobs{ Submit job }
The way I'm tackling this at the moment is to replace the foreach job loop with a loop like this:
#Job.sh read arg while [ arg != TERMINATE ] do (submit job arg) read arg done

The real crux of the question is this: How do I run the above shell script from a Perl script, then make it wait for input from STDIN whilst allowing the perl script to keep running? Currently, I've got something like this, which obviously doesn't work..:

#SubmitJob.pl use strict; use warnings; my @jobs; # do some stuff here... ... # run the shell script `./Job.sh`; # generate the jobs.. @jobs=... # print the jobs to STDOUT so that they can be picked up by the shell +script: foreach my $job (@jobs){ print $job; } exit 0;

Now, I understand why this doesn't work (the Perl script won't keep running if the shell script is started in the foreground, but the shell script won't accept input from STDIN if it's started in the background). But I don't know how to make it do what I want. My only thought was a fork---is this appropriate? Or can someone suggest a whole new approach to doing this?

thanks, why_bird

edit changed title to avoid confusion; readmore'd some text

........
Those are my principles. If you don't like them I have others.
-- Groucho Marx
.......