Java call system execution program (OS Command)

xiaoxiao2021-03-06  14

The following code can be shipped in Windows 2000. Sayhi.exe is any one of the execution programs. Public static void main (string args []) {string s = null; // system command to run string cmd = "cmd /cc:/sayhi.exe"; // set the working directory for the OS Command Processor File Workdir = New file ("c: //"); try {processim (). EXEC (CMD, NULL, WORKDIR); INT i = p.waitfor (); if (i == 0) {BufferedReader stdinput = New BufferedReader (p.GetInputStream ())))); // read the output from the command while ((s = stdinput.readline ())! = Null) {system.out.println (s);}} else {BufferedReader stdErr = new BufferedReader (new InputStreamReader (p.getErrorStream ())); // read the output from the command while (! (s = stdErr.readLine ()) = null) {System.out.println (s );}}} Catch (exception e) {system.out.println (e);}}

转载请注明原文地址:https://www.9cbs.com/read-49922.html

New Post(0)