File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ranch Office and the fly likes Running Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » This Site » Ranch Office
Bookmark "Running "top -b | grep idle " from a JAVA program" Watch "Running "top -b | grep idle " from a JAVA program" New topic

Running "top -b | grep idle " from a JAVA program

Sangeeta S

Joined: Jul 04, 2001
Posts: 3
We are trying to execute following four commands from within a Java Program.
But only first three are running i.e. 1, 2 and 3.
Can someone explain why the 4th command is not running and what will be the correct way?
1. Runtime.getRuntime().exec(new String[] {"/bin/sh","-c", "ls / 2>&1 | tee ls.log"});
2. Runtime.getRuntime().exec(new String[] {"/bin/sh","-c", "top -b 2>&1 | tee top.log"});
3. Runtime.getRuntime().exec(new String[] {"/bin/sh","-c", "ls / 2>&1 | grep auto"});
4. Runtime.getRuntime().exec(new String[] {"/bin/sh","-c", "top -b 2>&1 | grep idle"});
Thanks and sincere regards,
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
two things:
1. "Sangeeta S",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
2. This forum is for discussion of this web site. For general Java questions you should really ask in one of the specific forums. In this case I have moved your post to the "Unix/Linux" forum, which seems the most appropriate.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: Running "top -b | grep idle " from a JAVA program
It's not a secret anymore!