java - 从 Java 执行时 Pdflatex 运行崩溃(在 Windows 上)

标签 java latex pdflatex tikz

当我尝试从 Java 编译以下 Latex 文档时,我的 pdflatex 运行崩溃了:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\pagestyle{empty}
%
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,thin,black}]

\begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
    \node [int, pin={[init]above:$v_0$}] (a) {$\frac{1}{s}$};
    \node (b) [left of=a,node distance=2cm, coordinate] {a};
    \node [int, pin={[init]above:$p_0$}] (c) [right of=a] {$\frac{1}{s}$};
    \node [coordinate] (end) [right of=c, node distance=2cm]{};
    \path[->] (b) edge node {$a$} (a);
    \path[->] (a) edge node {$v$} (c);
    \draw[->] (c) edge node {$p$} (end) ;
\end{tikzpicture}

\end{document}

pdflatex 不仅会产生一些错误,而且会卡住。日志文件在中间被切断,甚至在封闭的引号完成之前(但我认为总是在相同的位置)。

我使用这个 Java 命令来执行 pdflatex:

Runtime.getRuntime().exec(command);
p.waitFor();

执行的命令是:

"C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe" -output-directory "C:\Eig\Lehre\Info2\ImagesTemp" "C:\Eig\Lehre\Info2\ImagesTemp\graph.tex"

在命令行中手动执行命令效果很好!此外,当我不在 latex 文档中包含 tikz 时,Java 执行工作正常。这对我来说似乎很奇怪 - 是有什么错误还是我遗漏了什么?

我在 Windows 上使用 Miktex 2.9 和 Java 8,我已经在不同的 Windows 版本上尝试过。

最佳答案

这个问题可能是由于没有捕获进程的输出造成的。您需要读取子进程写入标准输出和标准错误的每个字节,否则系统缓冲区将填满,进程将在下次尝试写入内容时阻塞。

这是一个相关问题:Capturing stdout when calling Runtime.exec

指向http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html获取更多信息。

关于java - 从 Java 执行时 Pdflatex 运行崩溃(在 Windows 上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33298548/

相关文章:

java - setTextColor() - 逻辑错误

java - Google Apps 脚本是否可以通过 HTTP POST 接收文件?

latex - 在 Latex 中将页眉/页脚插入章节页面

math - latex /Tikz : draw a vertical line to a straight line

latex - 如何摆脱投影仪中的导航栏

java - 以 O(log n) 复杂度计算一个值在排序数组中出现的次数

java - 使用 Guava 10 的谓词和函数接口(interface)与 GWT 2.4.0

latex - 使用 hyperref 时如何使超链接导航到 LaTeX 中的图形顶部?

latex - latex 中的除法方程

python - mac 上 python 子进程中的 pdflatex