wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes running linux find command through jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "running linux find command through jsp" Watch "running linux find command through jsp" New topic
Author

running linux find command through jsp

Sonal Joshiabc
Greenhorn

Joined: Aug 13, 2012
Posts: 3
Hi Guys,

I am trying to display names of all images in a particular directory (and all its subdirectories) using the below code.



The code is working fine but I am unable to get the image names in separate lines. Please help

Current Output:
abc.jpguntitled.JPGvivek.jpg

Required Output:
abc.jpg
untitled.JPG
vivek.jpg

Also I want to create links to images such that when abc.jpg is clicked, it should open in same window, say in the right half window. Please help.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

Please don't tell me that you want to do this in a professional webapp.

Not only is the practice of putting blocks of executable Java code in JSPs seriously discouraged, the java.io.File class has all the functionality needed to do a "find" operation in write-once/run-anywhere mode (including filtering names) and without the significant overhead of spawning an independent OS process.

As to why your sample is failing, however, I think it's because you're trying to read the command's input stream when you should be trying to read its output stream.


Customer surveys are for companies who didn't pay proper attention to begin with.
Sonal Joshiabc
Greenhorn

Joined: Aug 13, 2012
Posts: 3
Hi Tim,

I used locate command to find .jpg files


and used processbuilder to execute the command.
it is working now. Thanks for your reply
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Still, executing a native command in a JSP like this is an ugly, non-portable solution. Tim explained why:
Tim Holloway wrote:Not only is the practice of putting blocks of executable Java code in JSPs seriously discouraged, the java.io.File class has all the functionality needed to do a "find" operation in write-once/run-anywhere mode (including filtering names) and without the significant overhead of spawning an independent OS process.

Your solution is very inefficient, not scalable (when a lot of users use this functionality at the same time, lots of processes will be spawned on the server) and not portable (it will not work if you would have a server running Windows).

You can easily do this in pure Java using methods in the class java.io.File (look it up in the API documentation). That would make your code platform-independent and probably a lot faster.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: running linux find command through jsp
 
Similar Threads
Regarding reading a file in a jsp
Reading one line from a text
Remove unwanted double quote from .csv file
to read lines inside brackets
java read file problem