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";
}
}
Transcoding related
ret = new String (ret.getbytes ("GBK"), "Utf-8");
System.out.println ("return value" +ret);//Print
Java invoke command line execute Ruby Ruby file must be placed in project and directory