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
.......

In reply to Running a shell script from Perl, and making that shell script accept input from perl script. by why_bird

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.