【问题标题】:SSH to a windows server and run a command in that command serverSSH 到 Windows 服务器并在该命令服务器中运行命令
【发布时间】:2026-02-25 09:50:02
【问题描述】:

所以我有一组需要在 windows server 2003 中运行的命令(基本上是在 cmd 中运行 eclipse-webdriver java 代码的 ant 命令)。我希望通过单击按钮远程运行此命令。因此,我在安装了 ant、webdriver 的同一台服务器和应该运行命令的同一台服务器上用 perl 设置了一个网页。

因此,用户可以在他的个人笔记本电脑中打开网页并单击此按钮,并且 ant 命令应该在该远程 Windows 服务器中运行。

那么我如何从任何设备(基本上是 Windows 7)SSH(或连接)到该 Windows 服务器?

在 perl 中有没有办法可以连接到那个 windows 服务器?请帮忙。

【问题讨论】:

    标签: perl ssh network-programming cmd network-protocols


    【解决方案1】:

    有几个不同的模块可以用于 ssh,我喜欢 Net::OpenSSH,你可以这样做:

    my $ssh = Net::OpenSSH->new('username@192.168.0.19',password  => 'pass');   
    if ($ssh->error) {
      print "could not connect " . $ssh->error;
    } else {
       # Run a command
       my @dir_files = $ssh->capture('dir C:\temp');
       if ($ssh->error) {
         print "command fail " . $ssh->error;
       } else {
          print "@dir_files"; # should have the results of the command
       }
    }
    

    【讨论】: