Question regarding Runtime.exec()
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   smitha_shah
Posted On:   Sunday, September 9, 2007 09:41 AM

HI friends, I'm trying to convert a pdf to an eps file using Ghostscript in my servlet. I have given a part of my code WHen I run the servelet,I'm getting an error =3 . I have spent hrs looking up on the web and I'm not sure what's wrong. Please help me and it urgent . Note1: When I execute the command directly on command prompt. It works perfectly fine but when I call from my servlet , All I get is an empty eps file. NOte2:StreamGobbler is a helper class(which extends Thread) I have created to read the proc.inputstream() and using PrintWriter class to write to the output file Below is my code /*****************************************************/ protected void doGet(HttpServletRequest req, Htt   More>>

HI friends,
I'm trying to convert a pdf to an eps file using Ghostscript in my servlet. I have given a part of my code WHen I run the servelet,I'm getting an error =3 . I have spent hrs looking up on the web and I'm not sure what's wrong. Please help me and it urgent .

Note1: When I execute the command directly on command prompt. It works perfectly fine but when I call from my servlet , All I get is an empty eps file.

NOte2:StreamGobbler is a helper class(which extends Thread) I have created to read the proc.inputstream() and using PrintWriter class to write to the output file

Below is my code
/*****************************************************/
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

String[] commands = new String[4];
commands[0] = "C:\gs\gs6.15\bin\gswin32c";
commands[1] = "-sDEVICE=epswrite";
commands[2] = "-sOutputFile=/TestProject/test.eps";
commands[3] = "/TestProject/test.pdf";
FileOutputStream fos = new FileOutputStream("c:\tomcat5.0\webapps\TestProject\test.eps");

Process proc = Runtime.getRuntime().exec(commands);
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT", fos);
errorGobbler.start();
outputGobbler.start();
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
}

/***********************Output is **********************/
java.io.IOException: CreateProcess: C:gsgs6.15 ingswin32c -sDEVICE=epswrite
-sOutputFile=/tomcat5.0/webapps/TestProject/test.eps /tomcat5.0/weba
pps/TestProject/test.pdf error=3
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl. (ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
at java.lang.Runtime.exec(Runtime.java:591)
at java.lang.Runtime.exec(Runtime.java:464)
at com.demo.HelloExample.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)

/*********************End ***************************/

Any idea what error=3 means ? ANy suggestions to correct this error.

THanks for your time

   <<Less

Re: Question regarding Runtime.exec()

Posted By:   darryl_culverwell  
Posted On:   Wednesday, October 31, 2007 09:13 AM

If you are using tomcat
Have you enabled allowed exec() in your catalina.policy ?

Re: Question regarding Runtime.exec()

Posted By:   Christopher_Koenigsberg  
Posted On:   Tuesday, October 2, 2007 08:03 PM

maybe you need to add some command-line arg to tell 'gswin32c' that it should run completely non-interactively, not try to do anything like read or write the console? maybe that's what the error is from?



Otherwise, look up the documentation and/or source code for gs, and see where it might be exiting with status=3
About | Sitemap | Contact