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 -Ppasswordor
sql database -uUsername -Ppassword <file.sqli.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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |