开发者

i am trying to run a shell script from jsp but i am getting Ljava.lang.string error

I have the code in this way:

开发者_StackOverflow中文版
<% Process p;
 String[] cmd =  "Z:\\walmart\\environment.sh";

 try {    
   p = Runtime.getRuntime().exec(cmd);
   StringBuffer s = new StringBuffer();

   BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream)));     

   while (input.readLine() != null)  
   {
     s.append(input.readLine() + "\n");      
   } 

   System.out.println(s.toString()); 

 }
 catch (IOException e) {  
    System.err.println("Failed to read & or start "); 
 }  

%>


This

String[] cmd = "Z:\walmart\environment.sh";

should be

String[] cmd = {"Z:\walmart\environment.sh"};

It is an array of string. Not an array of char or a string!


1 - I think you need to escape the backslashes in your file path and make it an array:

String[] cmd = {"Z:\\walmart\\environment.sh"};

2 - Add a generic error handler to find out your error:

catch (Throwable th)     {  
     System.err.println("Error:"); 
     th.printStackTrace();
  }  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜