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

          評論

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

          主站蜘蛛池模板: 驻马店市| 当涂县| 屯留县| 台东县| 邯郸县| 湘潭县| 天峻县| 桓台县| 丰城市| 平度市| 塔城市| 涞水县| 南昌县| 普陀区| 山西省| 连云港市| 永泰县| 鸡东县| 扎鲁特旗| 岫岩| 宾阳县| 武平县| 陕西省| 永顺县| 青冈县| 柳江县| 皮山县| 寿光市| 定日县| 文安县| 察雅县| 黄骅市| 理塘县| 梨树县| 枞阳县| 新邵县| 秭归县| 伽师县| 乌兰县| 边坝县| 城固县|