⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex_exec.java

📁 JAVA分布式程序学习的课件(全英文)
💻 JAVA
字号:
// program to illustrate invoking a Unix shell to run a unix command 
//   from within a Java program

   import java.io.*;

class Ex_exec
{
	static PrintWriter screen = new PrintWriter(System.out, true);

	public static void main(String[] args) throws IOException
	{
           String s;
           String [ ] cmdarray;
           int number;
           cmdarray = new String[2];
           cmdarray[0] = "ls";
           cmdarray[1] = "-l";
           Process proc = Runtime.getRuntime().exec(cmdarray);
           /* If the subprocess takes input, this is how to write to it

           PrintWriter writeToShell
             = new PrintWriter (proc.getOutputStream());

           writeToShell.println("(load \"EBOOKS\")");
           */

           BufferedReader inputfromShell =
             new BufferedReader(new InputStreamReader
             (proc.getInputStream()));
           s = inputfromShell.readLine();
           while (s != null) {
              System.out.println(s);
              s = inputfromShell.readLine();
           }

           BufferedReader errorfromShell =
             new BufferedReader(new InputStreamReader
             (proc.getErrorStream()));
           s = errorfromShell.readLine();
           while (s != null) {
              System.out.println(s);
              s = errorfromShell.readLine();
           }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -