Runtime rt= Runtime.getRuntime() ;
Process p=rt.exec("add ur command line here") ;
p.waitFor() ;
int return_value =p.exitValue() ;
Process p=rt.exec("add ur command line here") ;
p.waitFor() ;
int return_value =p.exitValue() ;
怎么没有反应啊。
String passwd;
int count=0;
staff_id=Integer.parseInt(request.getParameter("acc_nbr"));
passwd=request.getParameter("passwd");
Runtime rt= Runtime.getRuntime() ;
Process p=rt.exec("/www/htdocs/netoffice/check "+staff_id+" "+passwd) ;
p.waitFor() ;
int return_value =p.exitValue() ;
if (return_value!=0)
{
System.out.println("密码错误!");
return;
}可是什么都没有,既没有进入正常页面,也没有出现"密码错误"的提示。我的操作系统是Linux;
int staff_id;
String passwd;
int count=0;
staff_id=Integer.parseInt(request.getParameter("acc_nbr"));
passwd=request.getParameter("passwd");
Runtime rt= Runtime.getRuntime() ;
Process p=rt.exec("/www/htdocs/netoffice/check "+staff_id+" "+passwd) ;
CheckStream csin = new CheckStream(p.getInputStream());
CheckStream cserr = new CheckStream(proInstall.getErrorStream());
csin.start();
cserr.start();
p.waitFor() ;
proInstall.destroy();
int return_value =p.exitValue() ;
if (return_value!=0)
{
System.out.println("ÃÜÂë´íÎó!");
return;
}
/**
* Êä³ö¿ØÖÆ̨ÐÅÏ¢µÄÏß³Ì
*/
class CheckStream extends Thread{ BufferedReader bufferedReader;
String lineRead = ""; /**
* Constructor needs an InputStream to form an anonymous
* InputStreamReader which is used to create a BufferedReader
* for reading the stream.
*/
CheckStream(InputStream is){
this.bufferedReader = new BufferedReader(new InputStreamReader(is));
} public void run(){
try{
while ((lineRead = bufferedReader.readLine()) != null){
showProcessInfo(lineRead);
}
}catch(Exception ioe){
}
}
}
可能是由于你的C程序输出的控制台信息,试试下面的代码int staff_id;
String passwd;
int count=0;
staff_id=Integer.parseInt(request.getParameter("acc_nbr"));
passwd=request.getParameter("passwd");
Runtime rt= Runtime.getRuntime() ;
Process p=rt.exec("/www/htdocs/netoffice/check "+staff_id+" "+passwd) ;
CheckStream csin = new CheckStream(p.getInputStream());
CheckStream cserr = new CheckStream(proInstall.getErrorStream());
csin.start();
cserr.start();
p.waitFor() ;
proInstall.destroy();
int return_value =p.exitValue() ;
if (return_value!=0)
{
System.out.println("ÃÜÂë´íÎó!");
return;
}
/**
* 输出控制台信息的线程
*/
class CheckStream extends Thread{ BufferedReader bufferedReader;
String lineRead = ""; /**
* Constructor needs an InputStream to form an anonymous
* InputStreamReader which is used to create a BufferedReader
* for reading the stream.
*/
CheckStream(InputStream is){
this.bufferedReader = new BufferedReader(new InputStreamReader(is));
} public void run(){
try{
while ((lineRead = bufferedReader.readLine()) != null){
showProcessInfo(lineRead);
}
}catch(Exception ioe){
}
}
}
BufferedReader bufferedReader;
^
/usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:67: Class InputStream not found.
CheckStream(InputStream is){
^
/usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:68: Class BufferedReader not found.
this.bufferedReader = new BufferedReader(new InputStreamReader(is));
^
/usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:73: Class BufferedReader not found in void run().
while ((lineRead = bufferedReader.readLine()) != null){
^
/usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:74: Method showProcessInfo(java.lang.String) not found in local class CheckStream (_0002foffice_0002ejspoffice_jsp_37. 1$CheckStream).
showProcessInfo(lineRead);
^
/usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:95: Class InputStream not found in new.
CheckStream csin = new CheckStream(p.getInputStream());
^
/usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:96: Undefined variable or class name: proInstall
CheckStream cserr = new CheckStream(proInstall.getErrorStream());
^
/usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:101: Undefined variable or class name: proInstall
proInstall.destroy();
错误更多了
java.io.BufferedReader需要引用
proInstall 改为 p
showProcessInfo() 去掉
你的问题最可能的原因就是由于你的C程序输出的控制台信息!
http://www.powerba.com/develop/web/java/article/20010630001.htm