Calling a another program from Java

S

Silveira Neto

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.
 
R

Roedy Green

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
 
J

Joshua Cranmer

Silveira said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top