"The command can also accept arguments via STDIN which would avoid this security problem, but I haven't been able to figure out how to do this with Capture::Tiny. If I have the password as a variable in my script, how can I pass this into STDIN for external command using Capture::Tiny."
In the following code, I've used cat as an example external command. This can read from STDIN. It outputs whatever it reads in to STDOUT: handy for this test; hopefully, your external command isn't echoing passwords.
#!/usr/bin/env perl use strict; use warnings; use autodie qw{:all}; use Capture::Tiny qw{capture}; my ($stdout, $stderr) = capture \&run_external_command; printf "STDOUT: %sSTDERR: %s\n", $stdout, $stderr; sub run_external_command { my $external_command = 'cat'; open my $cmd_pipe, '|-', $external_command; print $cmd_pipe "password\n"; }
Output:
STDOUT: password STDERR:
— Ken
In reply to Re: How to pass data as STDIN to Capture::Tiny
by kcott
in thread How to pass data as STDIN to Capture::Tiny
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |