Latex file: 0.tex content:
\documentclass{article}
\begin{document}
\begin{equation}
\frac{\partial p_{dyn}}{\partial n} = A
\end{equation}
\end{document}
Shell file: 0.sh content:
latex /u/b/basnet/Desktop/0.tex
dvipng /u/b/basnet/Desktop/0.dvi
Command in Terminal:
>chmod 755 /u/b/basnet/Desktop/0.sh
>/u/b/basnet/Desktop/0.sh
Output: Image, Dvi and other files generated by latex. You can see in the blue window.
Problem: This works only via terminal not by executing the command via Java program.
Java Program Code:
Runtime.getRuntime().exec("chmod 755 /u/b/basnet/Desktop/0.sh");
Runtime.getRuntime().exec("/u/b/basnet/Desktop/0.sh");
System.out.println("Script executed successfully");
Output:
run:
Script executed successfully
BUILD SUCCESSFUL (total time: 0 seconds)
The first line of the code i.e. making the file executable works fine as I cross-checked. But second line where the script file contains the latex command doesn't work when running via Java. I need to generate those files through my program.
答案 0 :(得分:1)
我想这需要对环境做些什么,我对所有这些操作系统的东西都不太深入,但我认为我的解决方案适用于我的电脑上的示例:
您必须将程序名称更改为在shell文件中使用的完整路径,因为Java运行时无法找到它们。例如:
/Library/TeX/texbin/latex /u/basnet/Desktop/0.tex
唯一出错的是,输出文件出现在tex文件所在位置的一个文件夹中,这意味着您必须更改输出目标或执行dvi的行。
如果您找不到程序的路径,请打开bash并输入
which latex
和
which diving