| Author |
trouble with Runtime.exec()
|
Jason Crest
Greenhorn
Joined: Oct 17, 2002
Posts: 29
|
|
i have a directory full of files that needs to be deleted every time my jsp is called so i am using is Runtime.exec() to do it i am trying to do it as follows Process p = Runtime.getRuntime().exec("del TEMP_FILES\*.*"); it works when i type it into the dos terminal, but it doesnt work from the jsp. maybe i just suck at dos or something, lol drop me a line thanks
|
 |
Jean-Francois Briere
Ranch Hand
Joined: Mar 03, 2004
Posts: 101
|
|
Why not simply doing:
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
|
|
1. your statement depends on the "current" directory to work correctly. In servlet/jsp you have no way to be sure what directory that is. 2. As I recall, del is a system command, not an executable program 3. What happens if one user is in the middle of something using the temp files and a new user enters the system? Bill
|
 |
Jason Crest
Greenhorn
Joined: Oct 17, 2002
Posts: 29
|
|
you make a good point. here is what im trying to do, im using the JFreeChart api in order to generate graphs of some data that i have. im not sure how to buffer these graphs directly to the browser so the user can view them. right now its set to generate a .png file. hence deleteing the temp images. but if there is a way i can buffer the output to the browser, that would work best i think here is some code that i have that pertains to generating the jfreechart and .png files. any suggestions? thanks [ June 29, 2004: Message edited by: Jason Crest ]
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
|
|
Normally this is done in two steps. 1. record the data that will be used to generate the image in a session and write the HTML page with <img src="theservleturlplussomekey" 2. When the browser does that image request, use the session information to create the PNG into a ByteArrayOutputStream (which creates a byte[] in memory), set the response headers to the content-length and content-type and send the binary image data. No file involved, everything in memory - automatically GCed. Bill
|
 |
Jason Crest
Greenhorn
Joined: Oct 17, 2002
Posts: 29
|
|
im not quite so good at doing the above, however i did try something like however, it doesnt display the image to the browser
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
|
|
Some browser are picky about having a content-length header set. Thats the primary reason for writing to an internal buffer first so you can set the length. resp.setContentType( typeString ); resp.setContentLength( sizeN ); Note those must be called BEFORE you send the byte[] that the ByteArrayOutputStream created. As I recall, .PDF viewers are also sensitive to getting the right size. Bill [ July 01, 2004: Message edited by: William Brogden ]
|
 |
 |
|
|
subject: trouble with Runtime.exec()
|
|
|