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