English 中文(简体)
不同的输出 - 在命令行运行数学文本时, 以及在使用 apache- commons- exec 从 java 程序执行命令时
原标题:Different output -- when running mathtext in command line and when the command is executed from a java program using apache-commons-exec

I am trying to run mathtext from a java program using apache-commons-exec. The problem is I am getting different output when I run the same command from a java program and when I run it through shell. so if run mathtext like this in the shell:

./mathtext test.png "$frac{{left( {{p^2} - {q^2}} 
ight)}}{2}$"

in a shell I get the perfect png but when I run the same thing using apache-commons-exec

Map map = new HashMap();    

        map.put("target", new File(trgtFileName));
        DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
        Executor exec = new DefaultExecutor();
        exec.setWorkingDirectory(/*I set the working directory where the mathtext is*/);
        CommandLine cl = new CommandLine("./mathtext"); 
        cl.addArgument("${target}");
        cl.addArgument(latex);
        cl.setSubstitutionMap(map);
//      Logger.log4j.info("command is:::"+cl.toString());
        ExecuteWatchdog watchdog = new ExecuteWatchdog(5000);
        exec.setWatchdog(watchdog);
        exec.execute(cl,EnvironmentUtils.getProcEnvironment(),resultHandler);
        resultHandler.waitFor();

我得到的图像,不是方程式,而是原TeX字符串:()

Can somebody please help me in solving the issue? I want to get the exact output. Thanks.

最佳回答

我发现问题在哪里:

$ 是 unix shell 的一个特殊字符, 而不是 Java 。 因此, 即使输入在命令行需要跳出 $, 例如 :

"$frac{{left( {{p^2} - {q^2}} 
ight)}}{2}$"

在Java程序内部,我不需要逃避美元或说 " (双重报价)在开始和结束时。

$frac{{left( {{p^2} - {q^2}} 
ight)}}{2}$

希望这能帮助某人:)

- - 手持者

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签