2012-05-24 2 views
0

apache-commons-exec을 사용하여 Java 프로그램에서 mathtext를 실행하려고합니다. 문제는 내가 java 프로그램에서 같은 명령을 실행할 때와 쉘을 통해 실행할 때 다른 결과를 얻고 있다는 것입니다. 쉘에서이 같은 그렇다면 실행 mathtext : 쉘에서다른 출력 - 명령 줄에서 mathtext를 실행할 때 및 apache-commons-exec를 사용하여 java 프로그램에서 명령을 실행할 때

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

나는 완벽한 PNG 를 얻을 수 있지만-간부 아파치 - 평민을 사용하여 같은 일을 실행할 때

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(); 

내가 얻을 이미지가 아닌 방정식하지만

누군가가 문제를 해결 좀 도와 주실 래요 원시 텍 문자열 :(? 나는 정확한 출력을 얻을 싶어요. 감사합니다.

답변

1

문제의 위치를 ​​파악했습니다 :

$는 java가 아닌 유닉스 쉘의 특수 문자입니다. 그래서 명령 줄에 입력 탈출해야하는 경우에도 $ 같은 : 나는 시작과 끝에 '$'또는 넣어 "(큰 따옴표)를 탈출 할 필요가없는 자바 프로그램 내

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

. 내가 좋아하는 명령을 넣어했다 :

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

희망이 누군가 :)

--Shankhoneer하는 데 도움이

관련 문제