jinfeng_wang

G-G-S,D-D-U!

BlogJava 首页 新随笔 联系 聚合 管理
  400 Posts :: 0 Stories :: 296 Comments :: 0 Trackbacks

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6550942

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4110242

===========Windows Okay========
import java.io.IOException;

 
public class aaaa {

 /**
  * @param args
  * @throws Exception
  */
 public static void main(String[] args) throws Exception {
  
  try {
   //String cmd = "\"C:/Program Files/Internet Explorer/iexplore.exe\"";
   String cmd = "C:/Program Files/Internet Explorer/iexplore.exe";
   Runtime.getRuntime().exec(cmd);
  } catch (IOException e) {
   e.printStackTrace();
   throw new Exception(e.getMessage());
  }
 }

}

  
=============Linux Error=========
import java.io.IOException;

public class aaaa {

 /**
  * @param args
  * @throws Exception
  */
 public static void main(String[] args) throws Exception {

  try {
   //String cmd = "/PlusData/1 2/1.sh";
   String cmd = "\"/PlusData/1 2/1.sh\"";
   System.out.println(cmd);

   Runtime.getRuntime().exec(cmd);
  } catch (IOException e) {
   e.printStackTrace();
   throw new Exception(e.getMessage());
  }
 }

 static boolean needsQuoting(String s) {
  int len = s.length();
  if (len == 0) // empty string have to be quoted
   return true;
  for (int i = 0; i < len; i++) {
   switch (s.charAt(i)) {
   case ' ':
   case '\t':
   case '\\':
   case '"':
    return true;
   }
  }
  return false;
 }

 static String winQuote(String s) {
  if (!needsQuoting(s))
   return s;
  s = s.replaceAll("([\\\\]*)\"", "$1$1\\\\\"");
  s = s.replaceAll("([\\\\]*)\\z", "$1$1");
  return "\"" + s + "\"";
 }

}

==============================

posted on 2007-05-18 14:27 jinfeng_wang 阅读(2160) 评论(1)  编辑  收藏 所属分类: java

评论

# re: java runtime.exec 无法处理引号的bug 2007-05-18 14:41 dreamstone
这样的问题发现困难啊,而且过程会用到大量的时间.呵呵..
谢谢分享  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: