AMADEUS html plain
This sketchy text is generated by AMADEUS
import java.util.*;
import java.io.*;
class WinExec
public class WinExec extends Exec
Autor: Lauri Kimmel
public WinExec(String osName)
public String execCommand(String[] args)
String result = "";
..try
!!
String[] cmd = new String[2];
õige interpretaatori valimine
..if
? osName.equals("Windows NT") || osName.equals("Windows XP")
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
<======
? osName.equals("Windows 95") || osName.equals("Windows 98")
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
<======
result = "\nNo specification for '" + osName + "'! Trying default ...";
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
String[] fullCmd = CommandLine.makeOneArray(cmd, args);
Runtime rt = Runtime.getRuntime();
result += "\nExecing '" + CommandLine.arrayToString(fullCmd) + "'\n";
//System.out.println("WinExec:execCommand:result="+result);
Process proc = rt.exec(fullCmd);
errorite lugeja
StreamGobbler errorGobbler =
new StreamGobbler(proc.getErrorStream(), "ERROR");
väljundi lugeja
StreamGobbler outputGobbler =
new StreamGobbler(proc.getInputStream(), "OUTPUT");
errorGobbler.start();
outputGobbler.start();
protsessi lõpu ootamine
int exitVal = proc.waitFor();
result += errorGobbler.getResult() + outputGobbler.getResult()
+ "\n\nExitValue: " + exitVal + "\n";
..catch
! (Exception e)
result = "\nTrouble in WinExec@execCommand: \n\t" + e;
<======result