webstart.java
来自「系统运行时的截屏图:webstart_screen01.gif/webstart」· Java 代码 · 共 208 行
JAVA
208 行
/**
* Copyright(c) 2005 Dragonfly - created by FengChun
* All Rights Reserved.
*
* Package: org.dragonfly.webstart
* FileName: WebStart.java
*
* Version: 1.0
* Created: 2005-5-13 21:32:28
* Updated: 2005-5-20 21:32:28
*
* Author: FengChun - f15_nsm@hotmail.com
* Description:
* Function:
*
*/
package org.dragonfly.webstart.runtime;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.dragonfly.webstart.util.DateTool;
public class WebStart {
private static ArrayList pList = new ArrayList();
public static synchronized ArrayList execDos(String command) throws WebStartException {
ArrayList lines = new ArrayList();
BufferedReader reader = null;
Process process = null;
try {
String line = "";
process =
Runtime.getRuntime().exec("cmd.exe /c " + command);
reader =
new BufferedReader(
new InputStreamReader(process.getInputStream()));
while ( (line = reader.readLine()) != null) {
lines.add(line);
}
process.waitFor();
}
catch (Exception e) {
e.printStackTrace();
throw new WebStartException();
}
finally {
try {
process = null;
if (reader != null) {
reader.close();
reader = null;
}
}
catch (Exception e) {
e.printStackTrace();
throw new WebStartException();
}
}
return lines;
}
public static synchronized Process runExe(String command) throws WebStartException{
if (command == null) {
return null;
}
Process process = null;
try {
process = Runtime.getRuntime().exec(command);
String startTime = DateTool.getNow().toLocaleString();
pList.add(new ExeProcess(command, process, startTime));
}
catch (Exception e) {
e.printStackTrace();
throw new WebStartException();
}
return process;
}
public static ExeProcess getExe(int index) {
if (index < 0) {
return null;
}
ExeProcess process = (ExeProcess) pList.get(index);
return process;
}
public static synchronized void stopExe(int index) {
if (index < 0) {
return;
}
Process process = null;
ExeProcess ep = (ExeProcess) pList.get(index);
process = ep.getProcess();
ep.setState(ExeProcess.STOPPED);
pList.set(index, ep);
if (process != null) {
process.destroy();
}
}
public static synchronized Process restartExe(int index) {
if (index < 0) {
return null;
}
ExeProcess ep = null;
ep = (ExeProcess) pList.get(index);
ep.setState(ExeProcess.RUNNING);
Process process = null;
try {
process = Runtime.getRuntime().exec(ep.getName());
ep.setProcess(process);
String startTime = DateTool.getNow().toLocaleString();
ep.setStartTime(startTime);
pList.set(index, ep);
}
catch (IOException e) {
e.printStackTrace();
}
return process;
}
public static synchronized void clearExe(int index) {
if (index < 0) {
return;
}
stopExe(index);
pList.remove(index);
}
public static synchronized void clearExeList(String exeList) {
if (exeList.length() == 0) {
return;
}
ExeProcess ep = null;
ArrayList al = new ArrayList();
for (int i = 0; i < pList.size(); i++) {
if ((exeList+",").indexOf(i + ",") == -1) {
ep = (ExeProcess) pList.get(i);
al.add(ep);
}else{
stopExe(i);
}
}
pList = al;
}
public static synchronized void clearAll() {
pList.clear();
}
public static ArrayList getRunningExeList() {
ArrayList a = new ArrayList();
for (int i = 0; i < pList.size(); i++) {
ExeProcess ep = (ExeProcess) pList.get(i);
if (ep.getState() == ExeProcess.RUNNING) {
a.add(ep);
}
}
return a;
}
public static ArrayList getStoppedExeList() {
ArrayList a = new ArrayList();
for (int i = 0; i < pList.size(); i++) {
ExeProcess ep = (ExeProcess) pList.get(i);
if (ep.getState() == ExeProcess.STOPPED) {
a.add(ep);
}
}
return a;
}
public static ArrayList getExeList() {
return pList;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?