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

          評論

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

          主站蜘蛛池模板: 广西| 桓仁| 荣昌县| 宾阳县| 宜城市| 胶州市| 新乡市| 河间市| 多伦县| 黔西县| 河北区| 襄城县| 宽城| 昔阳县| 石狮市| 蒲江县| 凤庆县| 渭南市| 岚皋县| 都兰县| 南木林县| 枣强县| 喀喇沁旗| SHOW| 观塘区| 中山市| 丽水市| 女性| 灌阳县| 大余县| 大同县| 沐川县| 东方市| 建德市| 南涧| 枞阳县| 宜宾市| 天津市| 杨浦区| 筠连县| 墨江|