简体   繁体   English

Linux从Java查找命令不起作用

[英]Linux find command from java not working

Can anyone help me get this code working in linux 任何人都可以帮我在Linux上运行此代码

    public static void main(String[] args) throws Exception,{   
    String s ="find . -exec ls -al {} \\;";
    Process exec = Runtime
            .getRuntime()
            .exec(s);
    exec.waitFor();
System.out.println(s);
    if (exec.getErrorStream().available() != 0) {
        BufferedInputStream bf = new BufferedInputStream(
                exec.getErrorStream());
        DataInputStream din = new DataInputStream(bf);
        System.out.println(din.readLine());
    }

    System.out.println(exec.exitValue());
}

I am getting the following output. 我得到以下输出。

find . -exec ls -al {} \;
find: missing argument to `-exec'
1

Try using this: 尝试使用此:

String[] params = {"find", ".", "-exec", "ls", "-al", "{}", ";"};

instead of your plain String command. 而不是简单的String命令。

Be careful though: The output is heavy (I tested with /dev/.) and the waitFor method may cause your I/O Buffer to burst. 但是请注意:输出很重(我已经使用/ dev /进行了测试),并且waitFor方法可能会导致您的I / O缓冲区爆裂。

反斜杠太多

find . -exec ls -al {} ';'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM