Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Calling a another program from Java

Thread view: 
Silveira Neto - 21 Sep 2007 19:24 GMT
Hi guys,
I'm trying to call a program by an Java programming. Like a terminal
command like "rm -rf thing" or "ls" or "firefox", and get its output.
Just that.
In C I do that with system("ls -la|grep something > somefile.txt"). I
know that I'll lose some portability if I use pipes, but I need them.
Silveira Neto - 21 Sep 2007 19:39 GMT
Oh sorry, finally I found (in the message before mine). The
Runtime.getRuntime.exec("ls -la").
If someone wants, is there:
http://www.rgagnon.com/javadetails/java-0014.html

And I guess using streams its possible to make it still portable and
not use pipes.

Thanks.
Roedy Green - 21 Sep 2007 23:50 GMT
On Fri, 21 Sep 2007 18:24:01 -0000, Silveira Neto
<silveiraneto@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>I'm trying to call a program by an Java programming. Like a terminal
>command like "rm -rf thing" or "ls" or "firefox", and get its output.
>Just that.
>In C I do that with system("ls -la|grep something > somefile.txt"). I
>know that I'll lose some portability if I use pipes, but I need them.

see http://mindprod.com/jgloss/exec.html

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Joshua Cranmer - 22 Sep 2007 00:29 GMT
> Hi guys,
> I'm trying to call a program by an Java programming. Like a terminal
> command like "rm -rf thing" or "ls" or "firefox", and get its output.
> Just that.
> In C I do that with system("ls -la|grep something > somefile.txt"). I
> know that I'll lose some portability if I use pipes, but I need them.

You'll also lose portability by using "ls" : Windows does not support
the ls command.

If you want to manipulate file hierarchies, java.io.File can help you
with that in a truly cross-platform manner.

Signature

Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.