Executing external program through JSP

R

ruds

Hi,
I want to call an external program through JSP.In which I have to
convert documents to PDF as a part of it.
For this I'm using Runtime class to execute my command,but there is no
action from the JSP.

My code is:
<%@ page import="java.io.*,java.uti.*"%>

<%
String file="C:\\1.doc";

String s = "C:\\Program Files\\PDFCreator\\PDFCreator.exe /NOSTART /PF
\""+file+"\"";
try{
Process p = Runtime.getRuntime().exec(s);
}catch(Exception e){}
out.println("Files converted");
%>

Please tell me where i'm going wrong.
If I run it through cmd or a java class it works fine.
 
A

Andrew Thompson

...
I want to call an external program through JSP.In which I have to
convert documents to PDF as a part of it.
For this I'm using Runtime class to execute my command,but there is no
action from the JSP.

My code  is:
<%@ page import="java.io.*,java.uti.*"%>

<%
        String file="C:\\1.doc";

        String s = "C:\\Program Files\\PDFCreator\\PDFCreator.exe /NOSTART /PF
\""+file+"\"";
        try{
        Process p = Runtime.getRuntime().exec(s);

You might find out a powerful load by *not*
ignoring exceptions!
        }catch(Exception e){}

// should be..
}catch(Exception e){
e.printStackTrace();
}

And it might also make sense to wait for the
Process to finish.
 
R

ruds

You might find out a powerful load by *not*
ignoring exceptions!


// should be..}catch(Exception e){

  e.printStackTrace();

}

And it might also make sense to wait for the
Process to finish.

I have tried to print the stack trace too. But it does'nt give any
message.
I have also printed the OutputStream and InputStream:

out.print("Output Steam:"+p.getOutputStream());
out.print("\nInput Steam:"+p.getInputStream());

This just gives me the BufferedOutputStream@73e341 and
BufferedIputStream@.....

even p.waitFor(); has'nt give any different result.
 
R

ruds

In fact if I use p.waitFor(); then the execution time required is more
than 15 mins with no required output.
 
A

Arne Vajhøj

ruds said:
I have also printed the OutputStream and InputStream:

out.print("Output Steam:"+p.getOutputStream());
out.print("\nInput Steam:"+p.getInputStream());

This just gives me the BufferedOutputStream@73e341 and
BufferedIputStream@.....

Yes.

What were you expecting to see?

If you want the programs output then you need to
actually read from the stream.

The programs error stream could obviously also be
relevant.

Arne
 
A

Arne Vajhøj

ruds said:
In fact if I use p.waitFor(); then the execution time required is more
than 15 mins with no required output.

Are you sure the command you execute runs without any input?

Arne
 
R

ruds

Are you sure the command you execute runs without any input?

Arne

The input for my program is the 'file' parameter, as written in the
code provided i.e.:

String file="C:\\1.doc";
String s = "C:\\Program Files\\PDFCreator\\PDFCreator.exe /NOSTART /PF
\""+file+"\"";

And then I execute the program which is PDFCreator.exe.
 
R

ruds

I have read somewhere that to execute external program through Tomcat
I have to check the "Allow service to interacte with desktop" in
Tomcat properties as well as the service has to be started as an
Administrator.
My log-on account is added in the administrators list and I have
checked the "Allow service to interacte with desktop" too.
But still the program is not executing :(
Please help.
 
R

ruds

I'm now able to call the class file from JSP by adding the class file
in package.
The program that I'm calling to execute is also executed but I'm not
getting the output i.e in this case a PDF file is not printed.
In the Java program that I'm calling through JSP, threads are being
used to execute the PDF printer.Is this creating any problems?
Please suggest. It is very urgent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top