English 中文(简体)
利用SSH,从另一个永久档案中边远执行一个永久档案和通过含有空间的论点的最佳途径是什么?
原标题:Using SSH, what is the best way to remotely execute a perl file from another perl file and pass arguments that contain spaces?

Here is what I have- A CGI script on server A gets the parameters entered in a webform, creates a remote ssh command that calls another perl file on server B and passes all parameters as arguments to the ash command. Perl file on server B parses arguments n operates thereafter.

现在,既然我已赢得所有参数,我就具有“=”等特性,在服务器A和服务器B处理之前,由国际地理信息学组织的每个参数加上“=”。

然而,这未能达到能够有空间的参数。 为了纠正这种情况,我可以附上在////......范围内的每一参数(主要是为了逃避“,然后是为了逃避其他冲突”的斜线),然后在我对“=”(如果我附上每条通道,可能会被抛弃),但这是我想要达到的最佳办法吗?

最佳回答
问题回答

http://search.cpan.org/perldoc?Net%3a%3aOpenSSH”rel=“nofollow”Net:OpenSSH,它将照顾以下引文:

use Net::OpenSSH;

my $ssh = Net::OpenSSH->new($host);
my ($out, $err) = $ssh->capture2($cmd, @args);

我使用守则

sub text_to_shell_lit(_) {
   return $_[0] if $_[0] =~ /^[a-zA-Z0-9_-]+z/;  # Optional
   for (my $s = $_[0]) {
      utf8::downgrade($_);  # Check for non-bytes
      die if //;          # Check for NUL
      s/ / \  /g;
      return " $_ ";
   }
}

my $remote_cmd = join    , map text_to_shell_lit,
   perl => (  -e  => $perl_code,  -- , @args );

my @ssh_cmd = (ssh => (  -- , $remote_target, $remote_cmd ));
   -or-
my $ssh_cmd = join    , map text_to_shell_lit,
   ssh => (  -- , $remote_target, $remote_cmd );

但是,你可以使用。 String:Shell Quote s shell_quote und text_to_shell_lit

use String::ShellQuote qw( shell_quote );

my $remote_cmd = shell_quote
   perl => (  -e  => $perl_code,  -- , @args );

my @ssh_cmd = (ssh => (  -- , $remote_target, $remote_cmd ));
   -or-
my $ssh_cmd = shell_quote
   ssh => (  -- , $remote_target, $remote_cmd );




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...