Pdflatex run crashes when executed from Java (on Windows)

喜欢而已 提交于 2019-12-11 00:47:06

问题


When I try to compile the below Latex document from Java, my pdflatex run crashes:

\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 doesn't just produce some error, but it simply freezes. The log file is cut off in the middle, even before an enclosing quotation mark is completed (but always at the same position, I think).

I use this Java command to execute pdflatex:

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

The command executed is:

"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"

Executing the command by hand in a command line works fine! Also, the Java execution works fine when I don't include tikz in the latex document. This seems quite strange to me - is there some bug or am I missing something?

I'm using Miktex 2.9 and Java 8 on Windows, I've tried it on different Windows versions.


回答1:


This problem is probably caused by not capturing the output of the process. You need to read every byte written to standard out and standard error by the child process else the system buffer will fill up and the process will block when it next attempts to write something.

Here's a related question: Capturing stdout when calling Runtime.exec

Which points to http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html for more information.



来源:https://stackoverflow.com/questions/33298548/pdflatex-run-crashes-when-executed-from-java-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!