【问题标题】:Errant error output behavior with perl execute bash scripts on a remote machineperl 在远程机器上执行 bash 脚本时的错误输出行为
【发布时间】:2016-07-16 21:10:44
【问题描述】:

我的 perl 脚本中有这一行,它连接到远程机器并执行 bash 脚本:

system("ssh -t remotemachine /dir/dir/bashscript");

在我的 bash 脚本中,我使用退出代码 2 some commands 2 >> error.txt 来捕获我可能遇到的任何错误,并且我希望将这个 error.txt 写入存储 bash 脚本的同一文件夹中。

我的问题是当我 ssh 进入机器并从终端运行程序时,可以捕获错误并将其写入 error.txt 但是如果我从我的 perl 运行程序,程序能够运行但错误没有被捕获。

有什么建议吗?

【问题讨论】:

    标签: linux bash perl shell


    【解决方案1】:

    使用捕获文件的完整路径。

    some commands 2 >> /dir/dir/error.txt
    

    否则该文件将在用户 $HOME 中创建(如果存在)。

    【讨论】:

      猜你喜欢
      • 2013-12-04
      • 2013-08-16
      • 2011-06-30
      • 2015-05-03
      • 2021-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多