【问题标题】:Linux command not working when changing servers更改服务器时Linux命令不起作用
【发布时间】:2013-09-13 07:01:18
【问题描述】:

我目前正在更改我们的系统以使用另一台服务器来获取文件(为跟踪某些内容而生成的文件,并不重要)。这个系统是基于java的,获取这些文件的代码是使用Linux commandos。获取这些文件的代码是:

session = connection.openSession();
session.execCommand("ls -B -A " + filelocation);
output = new BufferedReader(new InputStreamReader(new StreamGobbler(session.getStdout()), "UTF-8"));

这在我们的原始服务器(x86_64 GNU/Linux)上确实有效,但在“新”服务器(SunOs 5.10 Generic January)上无效。在 SunOS 服务器上运行此命令时,我得到:

ls: illegal option -- B
usage: ls -1RaAdCxmnlhogrtuvVcpFbqisfHLeE@ [files]

我对命令行很不熟悉,而且我还没有编写原始代码。但这是我想的

-A, --almost-all           Do not list implied . and ..
-B, --ignore-backups       Do not list implied entries ending with ~

有没有一种可选的方法可以让它在 SunOS 服务器上运行?

编辑

检查读取的每个字符串 if line.endsWith("~");

while ((outputString = output.readLine()) != null) {
    if(!outputString.endsWith("~")){
         fileList.add(outputString);                     
    }
}

【问题讨论】:

    标签: java linux command-line ls sunos


    【解决方案1】:

    您也可以编写一个 shell 脚本 new_ls 调用 ls 并删除以“~”结尾的行

    或者当您在 java 中处理结果时,您还可以通过检查每个 String 读取 if line.endsWith("~"); 来忽略从 BufferedReader 读取的行;

    【讨论】:

    • 我认为我会远离编写 shell 脚本。但是当检查每个字符串时,如果行以〜结尾,这是否意味着我应该在命令中删除 -B: session.execCommand("ls -A " + filelocation); ?我还编辑了帖子以获取更多代码信息,这是你的意思结束的用法吗?
    猜你喜欢
    • 1970-01-01
    • 2019-01-27
    • 2016-11-13
    • 2020-11-25
    • 2018-08-19
    • 1970-01-01
    • 1970-01-01
    • 2014-07-09
    • 2017-06-26
    相关资源
    最近更新 更多