Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Ubuntu的Runtime.exec()时的正确Java路径_Java - Fatal编程技术网

使用Ubuntu的Runtime.exec()时的正确Java路径

使用Ubuntu的Runtime.exec()时的正确Java路径,java,Java,如何给出Ubuntu的runtime.exec的路径?执行以下程序时,我没有得到输出: import java.io.IOException; public class Modify { public static void main(String args[]) { Runtime rt = Runtime.getRuntime(); try { rt.exec("java -jar home/srinathm/srinath

如何给出Ubuntu的runtime.exec的路径?执行以下程序时,我没有得到输出:

import java.io.IOException;

public class Modify {

    public static void main(String args[]) {
        Runtime rt = Runtime.getRuntime();
        try {
            rt.exec("java -jar home/srinathm/srinath/invalidxml/atlassian-xml-cleaner-0.1.jar home/srinathm/srinath/invalidxml/FAR4031_V_rdf.xml >home/srinathm/srinath/invalidxml/data-clean.xml");

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}
在他的代码中,不会生成data-clean.xml


任何帮助都将不胜感激。

我猜您的道路上没有Java。如果不知道实际的错误消息是什么,很难判断

尝试使用/usr/bin/java,看看这是否有帮助,如下所示:

rt.exec("/usr/bin/java -jar home/srinathm/srinath/invalidxml/atlassian-xml-cleaner-0.1.jar home/srinathm/srinath/invalidxml/FAR4031_V_rdf.xml >home/srinathm/srinath/invalidxml/data-clean.xml");

公共静态字符串参数[]{

    try {
        ProcessBuilder builder = new ProcessBuilder(new String[]{"java","-jar","/atlassian-xml-cleaner-0.1.jar","/home/srinathm/invalid xml/FAR4031_V_rdf.xml"});
            builder.redirectErrorStream(true);
            Process p = builder.start();

            BufferedInputStream in = null;
            FileOutputStream out = null;

            try {
               in = new BufferedInputStream(p.getInputStream());
               out = new FileOutputStream("/home/srinathm/srinath/invalidxml/output.xml");

               int c;
               while ((c = in.read()) != -1) {
                  out.write(c);
               }
            }finally {
               if (in != null) {
                  in.close();
               }
               if (out != null) {
                  out.close();
               }
            }


    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

我正在使用streamsJava的外部进程执行工具不是shell,它们不理解诸如>”之类的重定向操作符。我建议您切换到ProcessBuilder,它可以直接重定向到文件:

ProcessBuilder pb = new ProcessBuilder("java", "-jar",
  "home/srinathm/srinath/invalidxml/atlassian-xml-cleaner-0.1.jar",
  "home/srinathm/srinath/invalidxml/FAR4031_V_rdf.xml");
pb.redirectOutput(new File("home/srinathm/srinath/invalidxml/data-clean.xml"));
pb.redirectError(ProcessBuilder.Redirect.INHERIT); // send process stderr to java's stderr
Process p = pb.start();
p.waitFor();

您得到的任何异常/错误?在命令提示符下发出命令时不生成,它是用我的代码生成的,但不是从java生成的generating@SrinathMunna对不起,我不明白。