Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to call a script interactively from perl

by zentara (Archbishop)
on Oct 09, 2012 at 12:09 UTC ( #997997=note: print w/ replies, xml ) Need Help??


in reply to How to call a script interactively from perl

Here is a simple usage of IPC::Open3 showing how to write to your STDIN.

#!/usr/bin/perl use warnings; use strict; use IPC::Open3; #interface to "units" calculator #my $pid = open3(\*WRITE, \*READ, \*ERROR,"units -t"); #terse output my $pid = open3(\*WRITE, \*READ, 0 , "units -t"); #if \*ERROR is set to 0, STDERR is sent to STDOUT #chomp(my $prompt = <READ>); #print "$prompt\n"; foreach ( '100 yards', '1 mile', '1 kilometer', '1 parsec', '1 foobar' +){ print WRITE "$_\n meters \n"; chomp(my $answer = <READ>); print "$_ = $answer meters\n"; } __END__

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh


Comment on Re: How to call a script interactively from perl
Download Code
Re^2: How to call a script interactively from perl
by LetMeAsk (Initiate) on Oct 15, 2012 at 21:14 UTC
    Thanks all for the answers, let me detail the situation again, The third party script after completion (first round) ask a question:
    Select Option :
    Manually if i supply an "X" then it quits the script but as i am calling this third party script from my perl script i want perl to terminate that script so that the output of the thirdpartyscript can be written to a file(by perl) and so that i can use that file. Sorry if you replied to the exact scenario. Thanks
      You have me confused. How can you terminate the script in a way that allows it to output to a file? You need to describe in exact detail how this third party script runs. Maybe you are looking to put the process in the background, i.e. a background process?

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh
        I am sorry to confuse you, ok here i go again: There is an existing script (Lets call it ThirdPartyScript and i cannot do any modifications to it) which performs some processing and displays output on the STDOUT and at the end it asks for options. For example, when you provide an option "i" it means include flag and you can specify any search string. It then retrieves the results matching that search string from its database and after displaying those results it again wait for next action with the following prompt:
        Select option:
        Now, either you can provide next option as i (to include other search string or "d" to delete the listed results etc or "X" to quit script. Now, i am writing a perl script with the intention to run above thirdpartyscript with a specific search string from this perl code and write the result of this run to a unix file. Then again my perl code will email this output file to the interested parties. My perl code works fine when i run that for any other command (e.g. ls), but when i run that for the above third party script, it never completes execution and the output file never populated. So, i thought may be it is because the thirdpartyscript do not exit execution until an "x" is specified as explained above. Please let me know if it helps. Thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997997]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-12-20 20:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (97 votes), past polls