External process does not exit

R

ruds

Hi,
I'm calling a java class from JSP. The java class executes an external
program in this case PDFCreator.exe.
The JSP code executes and displays correct message, but this happens
before the PDFCreator exits.
Also the PDF Creator does not exit and hangs infinitely, without
converting the file to PDF which I intend to do.
I'm running this on Tomcat5.5 and Windows Citrix server.

Code for JSP FIle:
<%@ page import="java.io.*,java.util.*"%>
<%@ page import="pack.Test.*"%>
<%
try{
pack.Test t=new pack.Test(); //initialixe the java class
t.print();//call the function
}catch(Exception e) {e.printStackTrace();}
%>
<br>File Converted

Code for Test.java:
package pack;
import java.io.*;
import java.lang.Process;
import java.lang.Runtime;
import javax.servlet.*;
import javax.servlet.http.*;

public class Test
{
Process p;
Runtime r;
BufferedReader stdInput,stdError,br,buff,Input;
int i=0;

public void print()
{
String cmd="C:\\Program Files\\PDFCreator\\PDFCreator.exe /NOSTART /PF
\"C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\
\Reports\\1.doc\"";
System.out.println("In print="+cmd);
try{
p = r.getRuntime().exec(cmd);
//p.waitFor();
stdInput = new BufferedReader(new InputStreamReader(p.getInputStream
()));
stdError = new BufferedReader(new InputStreamReader(p.getErrorStream
()));
System.out.println("Input="+stdInput);
System.out.println("Error="+stdError);
} catch(IOException ioe){System.out.println("Exception="+ioe);}
//catch(InterruptedException ie){System.out.println("Exception="+ie);}
} //end of print fnction
} //end of class

Even if I dont use waitFor() then too the process continues for a long
time without any output.
What might be the cause of this problem?
The PDFCreator creates aPDF with 1 min if executed through cmd line or
through print command.
 
Joined
Feb 25, 2009
Messages
4
Reaction score
0
place the PDFCreator.exe in c:\temp and try

OR

cmd = "\"C:\\Program Files\\PDFCreator\\PDFCreator.exe\" /NOSTART /PF
\"C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\
\Reports\\1.doc\"";
 
Joined
Feb 25, 2009
Messages
4
Reaction score
0
place PDFCreator.exe in different place for example c:/tmp

or

"\"C:\\Program Files\\PDFCreator\\PDFCreator.exe\" /NOSTART /PF
\"C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\
\Reports\\1.doc\"";
 
D

Dave Miller

ruds said:
Hi,
I'm calling a java class from JSP. The java class executes an external
program in this case PDFCreator.exe.
The JSP code executes and displays correct message, but this happens
before the PDFCreator exits.
Also the PDF Creator does not exit and hangs infinitely, without
converting the file to PDF which I intend to do.
I'm running this on Tomcat5.5 and Windows Citrix server.

Code for JSP FIle:
<%@ page import="java.io.*,java.util.*"%>
<%@ page import="pack.Test.*"%>
<%
try{
pack.Test t=new pack.Test(); //initialixe the java class
t.print();//call the function
}catch(Exception e) {e.printStackTrace();}
%>
<br>File Converted

Code for Test.java:
package pack;
import java.io.*;
import java.lang.Process;
import java.lang.Runtime;
import javax.servlet.*;
import javax.servlet.http.*;

public class Test
{
Process p;
Runtime r;
BufferedReader stdInput,stdError,br,buff,Input;
int i=0;

public void print()
{
String cmd="C:\\Program Files\\PDFCreator\\PDFCreator.exe /NOSTART /PF
\"C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\
\Reports\\1.doc\"";
System.out.println("In print="+cmd);
try{
p = r.getRuntime().exec(cmd);
//p.waitFor();
stdInput = new BufferedReader(new InputStreamReader(p.getInputStream
()));
stdError = new BufferedReader(new InputStreamReader(p.getErrorStream
()));
System.out.println("Input="+stdInput);
System.out.println("Error="+stdError);
} catch(IOException ioe){System.out.println("Exception="+ioe);}
//catch(InterruptedException ie){System.out.println("Exception="+ie);}
} //end of print fnction
} //end of class

Even if I dont use waitFor() then too the process continues for a long
time without any output.
What might be the cause of this problem?
The PDFCreator creates aPDF with 1 min if executed through cmd line or
through print command.
If the String cmd works from the command line, you might try calling
cmd.exe and printing to it.
 
R

ruds

If the String cmd works from the command line, you might try calling
cmd.exe and printing to it.

--
Dave Miller
Java Web Hostinghttp://www.cheap-jsp-hosting.com/- Hide quoted text -

- Show quoted text -

I tried doing that too, stillnot working.
If I call it from JSP the JSP executes, PDFCreator is called but the
document is not converted to PDF nor the PDFCreator.exe stops.
I can see the PDFCreator running in my Windows Task Manager.
If I write a Thread.sleep(1000); and they call p.destroy(); the PDF
creator stooped but does not give output.
This is very urgent please suggest.
 
C

cbossens73

The PDFCreator creates aPDF with 1 min if executed through cmd line or
through print command.

It's not clear at all...

What if you manually invoke from the prompt the PDFCreator?
Does it also take one minute?

If not, what if you invoke *another* command from your JSP, like,
say, a copy command?

Does it execute correctly and fast?

If other commands are executed correctly and fast from your JSP
and if your PDFCreator executes correctly and fastly when you
invoke it manually from the command-line, I'd start by writing
a batch script that would wrap the PDFCreator command and try
invoking that script. Make that script produce no output at
all at first.

Don't hesitate to report your findings and to tell us what
was wrong once you find the problem,
 
J

John B. Matthews

ruds said:
If the String cmd works from the command line, you might try calling
cmd.exe and printing to it.
[...]
I tried doing that too, still not working.

It doesn't work from the command line? That seems essential.

[...]
This is very urgent; please suggest.

You might look in trunk/Help/english/html/commandline.htm
 
R

ruds

To (e-mail address removed),
If I run it manuaaly through PDF creator then too it takes less than a
minute.
I tried invoking calc.exe, in the Java file and calling the function
from JSP, I can see the calc.exe is running in MS Task Manager but it
is not visible. nor does it stop executing when I call for a long time
without giving any output. I have tried this using servlet too as I
want to execute this on my server and not the client m/c.
Same thing happens for PDFCreator too. If I call Thread.sleep(1000)
and then p.destroy();, the PDF Creator is stopped immediadtely but
does not create the pdf file. :(

To John B. Matthews,
If I call PDF Creator from the cmd line directly (not through JAVA) it
gives the required o/p. But I'm invoking a Java function through JSP
which executes the PDFCreator.exe through cmd line it doesn't work.
cmd.exe it invoked as I can see it in my Task Manager, but nothing
else happens.

Code is:
public void print()
{
String cmd="C:\\WINDOWS\\system32\\cmd.exe /C C:\\Program Files\
\PDFCreator\\PDFCreator.exe /NOSTART /PF
\"C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\
\Reports\\1.doc\"";
try{
p = r.getRuntime().exec(cmd);

stdInput = new BufferedReader(new InputStreamReader(p.getInputStream
()));
stdError = new BufferedReader(new InputStreamReader(p.getErrorStream
()));
System.out.println("Input="+stdInput);
System.out.println("Error="+stdError);
} catch(IOException ioe){System.out.println("Exception="+ioe);
}

The PDF creator is executing but does not give any o/p.
Im using thesame command as given in help file of PDF Creator.
 
J

John B. Matthews

[...]
To John B. Matthews, If I call PDF Creator from the cmd line directly
(not through JAVA) it gives the required o/p. But I'm invoking a Java
function through JSP which executes the PDFCreator.exe through cmd
line it doesn't work. cmd.exe it invoked as I can see it in my Task
Manager, but nothing else happens.

Have you inspected the compiled JSP to see if the command is
processed correctly?

Browsing the relevant help file and looking at the /PF section,

Code is:
public void print() {
String cmd="C:\\WINDOWS\\system32\\cmd.exe /C C:\\Program Files\
\PDFCreator\\PDFCreator.exe /NOSTART /PF
\"C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\
\Reports\\1.doc\"";

I presume that the path is correct and that "There is NO space
between the parameter and the file name."
try{
p = r.getRuntime().exec(cmd);

stdInput = new BufferedReader(new InputStreamReader(p.getInputStream
()));
stdError = new BufferedReader(new InputStreamReader(p.getErrorStream
()));
System.out.println("Input="+stdInput);
System.out.println("Error="+stdError);
} catch(IOException ioe){System.out.println("Exception="+ioe);
}

The PDF creator is executing but does not give any o/p.
Im using thesame command as given in help file of PDF Creator.

Perhaps I'm overlooking it, but I see nothing to suggest that anything
will appear on standard output. Have you tried the /IF<input-filename>
/OF<output-filename> options?
 
R

ruds

Perhaps I'm overlooking it, but I see nothing to suggest that anything
will appear on standard output. Have you tried the /IF<input-filename>
/OF<output-filename> options?

Those options are used only when the i/p files are postscript or
bitmap files.
Still I tried using then but now even the PDFCreator is not
executing.. :(
 
J

John B. Matthews

ruds said:
Those options are used only when the i/p files are postscript or
bitmap files. Still I tried using then but now even the PDFCreator is
not executing. :(

Well, you know how to make it work from the command line; presently,
you know it doesn't work as a JSP. Perhaps you might try the middle
path: see if you can exec it from a plain old Java program:

<http://groups.google.com/group/comp.lang.java.programmer/msg/3a52ecfb9ab8fc1f?hl=en>
<http://mindprod.com/jgloss/exec.html>

Then try from a servlet. Use this iterative approach to see where
things go awry.
 
R

ruds

Perhaps you might try the middle path: see if you can exec it from a plain old Java program:
It works from a standalone java program, but If I call the Java
program through a JSP it does'nt work.

Then try from a servlet. Use this iterative approach to see where things go awry.
I have tried using servlet too, same thing happens:
PDFCreator is seen running in the background but no output is
generated, nor it stops executing for a long time.
If I use Thread.sleep(1000); then Thread.destroy(); the [rogram
does'nt wait that long and destroys the PDFCreator immediately.
 
J

John B. Matthews

ruds said:
Perhaps you might try the middle path: see if you can exec it from a
plain old Java program:
It works from a standalone java program, but If I call the Java
program through a JSP it does'nt work.
Then try from a servlet. Use this iterative approach to see where
things go awry.
I have tried using servlet too, same thing happens: PDFCreator is
seen running in the background but no output is generated, nor it
stops executing for a long time. If I use Thread.sleep(1000); then
Thread.destroy(); the [rogram does'nt wait that long and destroys the
PDFCreator immediately.

I don't use Windows, but do you need to exec cmd? E.g.

String cmd="cmd C:\\Program Files\\PDFCreator\\PDFCreator.exe..."
 
R

ruds

String cmd="cmd C:\\Program Files\\PDFCreator\\PDFCreator.exe..."

No change the cmd executes but then PDFCreator does not...
OK.
I'll just try to print using *.dll file through command line.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top