Worthy monks please forgive this intrusion by a novice seeking wisdom ...

I have arrived at a new chapter and been given responsibility for maintaining a perl script. This script is a long and faithful servant that does various things but at it's core it executes various system commands on a linux box

To facilitate this it makes use of use IO::CaptureOutput qw(capture_exec_combined);

The code does the following:

my @command = ( $command, $param1, $param2, ) my ( $stdout, $success, $exit_code ) = capture_exec_combined(@command) +;

This works for all the existing commands that we have because they can all be mapped into the necessary elements

So for example (simplified for the purpose of demonstration):

Linux 'ls file*.txt' becomes $command = 'ls', $param1 = 'file*.txt' and it does all the right things (i.e. $stdout contains a list of files that match files*.txt)

I now have to call a command in a database that can only be called in one of these two ways:

cat file.sql | sql database -uUsername -Ppassword

or

sql database -uUsername -Ppassword <file.sql

i.e. the necessary input can only come from stdin.

Obviously $command = 'sql', $param1 = 'database', $param2 = '-uUsername' and $param3 = '-Ppassword' (that bit is easy and works) but how do I feed it the contents of the file?

Is there a way to achieve this short of re-writing the existing framework in its entirety because the existing script is significantly larger, does everything else really well and this is only a minor but necessary modification?

As I said I am a novice supplicant seeking wisdom - thank you.


In reply to Using STDIN with IO::CaptureOutput by datamgmt

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.