Skip to content

Commit

Permalink
get output from java cmd execution
Browse files Browse the repository at this point in the history
  • Loading branch information
hbdhj committed Sep 2, 2013
1 parent 365fa58 commit fc23e76
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CmdOutput/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions CmdOutput/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CmdOutput</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions CmdOutput/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Mon Sep 02 21:01:23 CST 2013
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
Binary file added CmdOutput/bin/CmdOutput.class
Binary file not shown.
35 changes: 35 additions & 0 deletions CmdOutput/src/CmdOutput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class CmdOutput {
public static void main(String[] args)
{
try{
Runtime rt = Runtime.getRuntime();

Process proc = rt.exec("ls");

BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));

BufferedReader stdError = new BufferedReader(new
InputStreamReader(proc.getErrorStream()));

String line = null;
// read the output from the command
//System.out.println("Here is the standard output of the command:\n");
while ((line = stdInput.readLine()) != null) {
System.out.println(line);
}

// read any errors from the attempted command
//System.out.println("Here is the standard error of the command (if any):\n");
while ((line = stdError.readLine()) != null) {
System.out.println(line);
}
}catch(Exception e)
{
e.printStackTrace();
}
}
}

0 comments on commit fc23e76

Please sign in to comment.