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 閱讀(2161) 評論(1)  編輯  收藏 所屬分類: java

          評論

          # re: java runtime.exec 無法處理引號的bug 2007-05-18 14:41 dreamstone
          這樣的問題發現困難啊,而且過程會用到大量的時間.呵呵..
          謝謝分享  回復  更多評論
            

          主站蜘蛛池模板: 玛沁县| 滦南县| 客服| 盐边县| 乐清市| 祁东县| 榆社县| 大连市| 南宫市| 赫章县| 连平县| 宁德市| 宜春市| 鄂尔多斯市| 天全县| 沁阳市| 多伦县| 潼关县| 绩溪县| 隆德县| 安庆市| 温宿县| 睢宁县| 射阳县| 百色市| 白沙| 大安市| 沈丘县| 三穗县| 德惠市| 交口县| 乌拉特中旗| 大田县| 依兰县| 荥阳市| 内乡县| 临邑县| 冀州市| 哈巴河县| 赫章县| 肥西县|