简体   繁体   English

无法从Java运行乳胶的终端命令

[英]Unable to run terminal commands from Java for latex

Latex file: 0.tex content: 乳胶文件: 0.tex内容:

\documentclass{article}  
\begin{document}
\begin{equation}
\frac{\partial p_{dyn}}{\partial n} = A
\end{equation}  
\end{document}

Shell file: 0.sh content: Shell文件: 0.sh内容:

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. 输出:乳胶生成的图像,Dvi和其他文件。 You can see in the blue window. 您可以在蓝色窗口中看到。

在此处输入图片说明

Problem: This works only via terminal not by executing the command via Java program. 问题:这仅通过终端起作用,而不是通过Java程序执行命令。

Java Program Code: Java程序代码:

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 ie 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. 但是,通过Java运行时,脚本文件包含latex命令的第二行不起作用。 I need to generate those files through my program. 我需要通过我的程序生成这些文件。

I guess this has to do something with environment, I'm not too deep into all this OS stuff, but I think I have a solution which worked for your example on my pc: 我猜想这与环境有关,我对所有这些操作系统都不是很了解,但是我认为我有一个解决方案可以在您的PC上为您的示例工作:

You have to change the names of the programs to the full paths for the use in your shell-file, because the java runtime doesn't find them. 您必须将程序的名称更改为完整路径,以供您在Shell文件中使用,因为Java运行时找不到它们。 For example: 例如:

/Library/TeX/texbin/latex /u/basnet/Desktop/0.tex

The only thing that goes wrong is, that the output files appear one folder above where the tex file is located, which means you have to change either the output destination or the line for the dvi execution. 唯一出错的是,输出文件出现在tex文件所在位置的上方一个文件夹中,这意味着您必须更改输出目标或dvi执行的行。

If you don't find the path for the programs, open a bash and type 如果找不到程序的路径,请打开bash并键入

which latex

and

which diving

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM