Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2023-09-26 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?