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
用于更改目录的Java运行时命令&;编译LaTeX源代码不工作_Java_Terminal_Pdflatex - Fatal编程技术网

用于更改目录的Java运行时命令&;编译LaTeX源代码不工作

用于更改目录的Java运行时命令&;编译LaTeX源代码不工作,java,terminal,pdflatex,Java,Terminal,Pdflatex,我目前正在从事一个java项目,该项目使用LaTeX源代码自动生成文本文件。这些文件被写入硬盘驱动器的已知目录中。我想使用Runtime.getRunTime().exec(),而不是自己手动将LaTeX源代码编译成pdf 我下载并安装了BasicTeX。我知道它工作正常。我可以在一个新的终端窗口中调用以下内容,并且pdf正确生成,没有错误。像这样: Kyles-MacBook-Pro:~ kylekrol$ cd Documents/folder/Report Kyles-MacBook-Pr

我目前正在从事一个java项目,该项目使用LaTeX源代码自动生成文本文件。这些文件被写入硬盘驱动器的已知目录中。我想使用
Runtime.getRunTime().exec()
,而不是自己手动将LaTeX源代码编译成pdf

我下载并安装了BasicTeX。我知道它工作正常。我可以在一个新的终端窗口中调用以下内容,并且pdf正确生成,没有错误。像这样:

Kyles-MacBook-Pro:~ kylekrol$ cd Documents/folder/Report
Kyles-MacBook-Pro:Report kylekrol$ pdflatex latexDocument.txt
因此,在我的程序关闭之前,我只是尝试使用以下代码来编译pdf:

private static void compileLatexMac(String path) {
    String s = null;
    try {
        System.out.println("cd " + path.substring(0, path.length() - 1) + " && pdflatex latexDocument.txt");

        Process p = Runtime.getRuntime().exec("cd " + path.substring(0, path.length() - 1) + " && pdflatex latexDocument.txt");
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
        BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

        System.out.println("outputs:");
        while ((s = stdInput.readLine()) != null) {
            System.out.println(s);
        }

        System.out.println("errors:");
        while ((s = stdError.readLine()) != null) {
            System.out.println(s);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
当我运行这个程序时,我得到的只是以下内容,没有pdf或日志文件

cd /Users/kylekrol/Documents/folder/Report && pdflatex latexDocument.txt
outputs:
errors:
我真的不知道该怎么做,也不知道为什么它不起作用——特别是因为我可以从终端调用
cd/Users/kylekrol/Documents/folder/Report&&pdflatex latexDocument.txt
,它可以根据需要运行

如果有人能指出我遗漏了什么,那就太好了。谢谢


在双击jar文件运行时,我使用三个参数
exec()
命令遇到了更多问题。我通过调用下面的命令修复了这个问题,该命令使用一个额外的
pdflatex
参数,并且只使用绝对路径

Runtime.getRuntime().exec("pdflatex -output-directory=" + path.substring(0, path.length() - 1) + " " + path + "latexDocument.txt");

操作符
&&
由shell展开
Runtime.exec
不展开此运算符,只尝试执行
cd
命令,命令行的其余部分作为参数。因此,
pdflatex
命令永远不会运行


如果要使用特定的工作目录运行
pdflatex
,请使用
Runtime.exec

的,那么我应该如何编辑
&&
或使用什么其他操作符?对不起,我对这种情况很熟悉stuff@k.krol.27,看看。我几分钟前发现的,哈哈。谢谢,我现在开始工作了!