jinfeng_wang

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

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            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 閱讀(2161) 評(píng)論(1)  編輯  收藏 所屬分類: java

          評(píng)論

          # re: java runtime.exec 無(wú)法處理引號(hào)的bug 2007-05-18 14:41 dreamstone
          這樣的問題發(fā)現(xiàn)困難啊,而且過程會(huì)用到大量的時(shí)間.呵呵..
          謝謝分享  回復(fù)  更多評(píng)論
            

          主站蜘蛛池模板: 黄大仙区| 邵东县| 旺苍县| 美姑县| 新龙县| 遵化市| 溧水县| 蓬莱市| 鄱阳县| 怀柔区| 肃宁县| 尼木县| 宜黄县| 通化市| 杭锦后旗| 南华县| 宿松县| 景洪市| 兰溪市| 图木舒克市| 泰州市| 重庆市| 鄂伦春自治旗| 晋宁县| 沈阳市| 雅安市| 象山县| 资兴市| 蒙自县| 岳池县| 元朗区| 甘泉县| 红河县| 渝北区| 合江县| 大宁县| 丰台区| 雅安市| 仙居县| 灵武市| 新宁县|