?? phprunner.java
字號:
package org.xicabin.radcake.core.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class PHPRunner {
private String php;
public PHPRunner(String php) throws FileNotFoundException {
this.php = php;
if (!validate()) {
throw new FileNotFoundException("PHP executable not found.");
}
}
public boolean validate() {
File phpFile = new File(this.php);
return phpFile.exists() && phpFile.isFile();
}
public String getPHP() {
return this.php;
}
public String exec(String script) throws IOException {
Process phpProc = Runtime.getRuntime().exec(this.php);
OutputStreamWriter writer = new OutputStreamWriter(phpProc
.getOutputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(
phpProc.getInputStream()));
BufferedReader errReader = new BufferedReader(new InputStreamReader(
phpProc.getErrorStream()));
writer.write(script);
writer.flush();
writer.close();
String line = null;
String output = "";
while ((line = reader.readLine()) != null) {
output += line;
}
reader.close();
// TODO more helpful error message
String error = "";
while ((line = errReader.readLine()) != null) {
error += line;
}
errReader.close();
System.err.print(error);
return output;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -