import java.io.BufferedReader; import java.io.InputStreamReader;
public class CMD_RUBY { private static String exeCmd(String commandStr) { BufferedReader br = null; try { Process p = Runtime.getRuntime().exec(commandStr); br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } //System.out.println(sb.toString()); return sb.toString(); } catch (Exception e) { e.printStackTrace(); return "error"; } finally { if (br != null) { try { br.close(); } catch (Exception e) { e.printStackTrace(); } } } }
public static String post(String data) { String commandStr = "ruby post_data.rb \""+data+"\""; //String commandStr = "ipconfig"; return CMD_RUBY.exeCmd(commandStr); //return "123"; } }
转码相关
ret = new String(ret.getBytes("gbk"), "utf-8"); System.out.println("返回值"+ret);//打印
|
请发表评论