This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Getting MEAN with Mongo, Express, Angular, and Node and have Simon Holmes on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes runtime.exec() to call unix commands Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "runtime.exec() to call unix commands" Watch "runtime.exec() to call unix commands" New topic

runtime.exec() to call unix commands

rasica sharma

Joined: Jan 19, 2004
Posts: 3
i want to call unix commands like 'ls','mkdir' through java & store its result in a text file.
i tried to use runtime.exec() for it...but i dont get the correct output as needed...
If someone knows how to write the code, or even a link....
please....tell me...I need it urgently...
Yi Meng
Ranch Hand

Joined: May 07, 2003
Posts: 270
as in jcrontab:

Meng Yi
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17262

Hi Rasika. Unfortuantely your question isn't about the SCJD exam. I am going to move this thread to the Java-Beginner's forum.
I would really suggest that you avoid using runtime.exec to run OS specific commands. Since Java is write once run anywhere, you are breaking this rule and making it OS specific.
There is the File class that can get a list of files, and do some file stuff, as I am sure other classes already built that are OS independant that you can use to get the results you want.

Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
It is sorta covered in the JavaRanch Style Guide.
subject: runtime.exec() to call unix commands