如题
解决方案 »
- 纠结!!FCKeditor上传图片问题
- apache commons mail发送htmlemail 报错
- struts2问题 !在线求解
- 只用Spring能实现JMS吗?
- java问题 急急急
- struts2标签问题
- hql 数字四舍五入
- 我用hibernate的native sql ,但是总是出现 can't open connection?请大家指教
- 什么是servlet
- (我的分快没了)大家帮忙看看吧,我捣鼓一天了,筋疲力尽!!!为什么这个Struts始终徘徊在表单验证这里,不再往下走了,似乎Action的exce
- 使用sql语句进行数据库查询时,遇到这种情况该怎样解决?请指教!
- struct2的动态语言切换
该方法就可以的
代码如下:
//调用
Process p=Runtime.getRuntime().exec("/bin/bash ./make_package_rtx.sh ",null,new File(Main.destexepath));
new ControlThread(p.getErrorStream(),"ERROR","make_package_rtx.sh").start();
new ControlThread(p.getInputStream(),"INFO","make_package_rtx.sh").start(); int status = p.waitFor();
if(status == 0 )
{
RecordLog.logtool(Main.file,Main.type,"INFO", "end to build .");
}
else
{
RecordLog.logtool(Main.file,Main.type,"ERROR", "failed to build .");
throw new Exception("CallMakePackage.makepackage : ./*.sh or *.exe or *.bat execute failed . ");
}
//要单独的线程来监控
public class ControlThread extends Thread {
InputStream is;
String type;
String shell; /**
* 这个方法是个构造函数,\r\n
* 主要是初始化一些变量 \r\n
* @param is 输入流 主要有俩种 普通的输入流,错误流,
* @param type 传进来的是日志的表示 是error ,warning ,info等。
* @param shell 这个就是执行的脚本的名称
* @return no 没有返回值
* @author 刘欢
*/
ControlThread(InputStream is, String type,String shell)
{
this.is = is;
this.type = type;
this.shell= shell;
}
/**
* 这个只是重写了Thread 的 run 方法 。 \r\n
* 在这个方法中,将传进来的流读出来, 并写进日志文件中。\r\n
* @param no parameter
* @return no
* @author 刘欢
*/
public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
RecordLog.logtool(Main.file,Main.type,type, shell+" :"+line);;
} catch (IOException ioe)
{
ioe.printStackTrace();
}
}}
public static void main(String[] args) throws Exception {
// changeIp();
runtime.exec("perl D:/workOfEdit/PerlWork/bell.pl");
// InputStream inputStream = runtime.exec(
// "perl -e \"print \"HelloWorld!\";\" ").getInputStream();
InputStream inputStream = runtime.exec(
"perl D:/workOfEdit/PerlWork/HelloWorld.pl").getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(
inputStream));
String str = "";
while ((str = reader.readLine()) != null) {
System.out.println(str);
}
reader.close();
}