bash - How to properly escape characters for backquotes for ssh in Perl? -
i have code:
$script = "console.log(\"it works!\");"; $output = qx/ssh user@123.123.123.123 $script | interpreter/;
it's supposed run $script
through interpreter , write $output
. problem doesn't work. how escape characters correctly?
think you're trying ssh. both of these produce same output, work differently:
ssh user@host 'echo "puts 2+2" | ruby' echo "puts 2+2" | ssh user@host ruby
in first, remote shell executing pipeline. (if don't have single quotes, happens?) in second, it's piped through local shell ssh command , interpreter launched.
rather perform convoluted escapes of code come out correctly when crammed through sh, prefer pipe text in through stdin. it's simpler.
using ipc::run heavy lifting:
#!/usr/bin/env perl use strict; use warnings; use ipc::run qw(run); $in = <<ffff; 2 + 2 8 * (2 + 3) ffff $cmd = [qw(ssh user@host perl calc.pl)]; run $cmd, \$in, \my $out, \my $err or die "ssh: $?"; print "out: $out"; print "err: $err";
(calc.pl simple infix calculator program had lying around)
here's output get, running that:
out: 4 40 err: (ssh banners , pointless error messages)
seeing system
or qx//
calls in perl script sign of trouble. in general, don't having think shell syntax or shell quoting when i'm not writing shell; has nothing problem i'm trying solve, nor tool i'm solving with. (and that's ignoring security implications.)
oh, , if don't have muck standard input still want execute , capture output other programs, there's ipc::system::simple.
Comments
Post a Comment