Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Sangeeta S
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Sangeeta
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 http://www.javaranch.com/name.jsp . 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. Please don't post the same message to more than one forum. You obviously expect to read more than one forum - so do the people who might answer your question. This thread is now closed, all replies to the one in "Linux / Unix".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!