File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how to knoe if the files are being generated? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to knoe if the files are being generated?" Watch "how to knoe if the files are being generated?" New topic
Author

how to knoe if the files are being generated?

karan, chopra
Ranch Hand

Joined: Jun 05, 2001
Posts: 115
hi there,
i have servlet running on the server and the client communicates with the servlet to run an executable file on the server which in turns produces some output files on the server in some particular directory.now my question is the following:
the generation of the output files on the server is a proof of the fact that the executable file has run successfully on the server.now once the files are generated successfully i want to let the client know that the executable has run successfully and the files are generated.so can you please suggest me any ideas how can i do this?i know how to send an object to the frame from the servlet,but i need to test for some condition in the servlet before i send a string back to the frame from the servlet and depending upon that condition the string that is sent will be either "successful" or "unsuccessful".
i am using Runtime.getRuntime().exec(cmd) to run the executable on the server,but how do i check if this has executed correctly and hence send the "successful" string to the client or "unsuccessful" if it has not executed successfully?
any ideas would be appreciated..
cheers and thanks
karan
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
When you do an exec() you get back a Process object reference. From that Process you can get input streams that represent the normal out and err output streams, by looking at these you should be able to tell if the program executed as expected.
Bill
karan, chopra
Ranch Hand

Joined: Jun 05, 2001
Posts: 115
hi william,
following is the code that i have for running the exec:
try
{
if (windows)
{
// cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
Process p = Runtime.getRuntime().exec(cmd);
}

}
catch(IOException x)
{
// couldn't exec browser
System.err.println("Could not invoke browser, command=" + cmd);
System.err.println("Caught: " + x);
}
but whenever i try to print something out in the catch block then the program doesnt doesnt print anything..thats probably bcoz its not executing the catch block bcoz there are no exceptions generated,but suppose for some reason the executable file is not present in the dir in which the program expects it to be,what happens in such a situation.i have tried this situation and what happens in this case is that a small window pops up saying that "cannot open filename.exe",but no exception is generated.
please tell me as to how can i catch an exception that is generated when the executable is not present in the dir or for some reason it fails to start.would appreciate your help a lot..
thanks a lot
karan
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
I think the easiest way to detect the existance of the executable would be with a File object.
I notice that you have not taken my suggestion to get the input streams for the out and err output streams from the process. To quote the Process API "failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block and even to deadlock."
You also do not use the process waitFor method which is an alternative that waits for the process to finish if you are not handling the streams.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to knoe if the files are being generated?