• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

trouble with Runtime.exec()  RSS feed

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not simply doing:
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!