public class Linuxutils {
static Logger Logger = Logger.getlogger (Linuxutils.class);
public static string Execmd (string cmd) {
Logger.info (CMD);
String returnstring = "";
Runtime runtime = Runtime.getruntime ();
Process pro = null;
StringBuffer sb = new StringBuffer ();
if (runTime = = null) {
Logger.error ("Create runtime faliure!");
}
try {
Pro = Runtime.exec (cmd);
BufferedReader input = new BufferedReader (New InputStreamReader (
Pro.getinputstream ()));
String Line;
while (line = Input.readline ()) = null) {
Sb.append (line + "\ n");
}
returnstring = Sb.tostring ();
Logger.info (The result of "executing the +cmd+" command is: "+returnstring);
Input.close ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
return returnstring;
}
}
String ls = linuxutils.execmd ("ls-l" + path);
Char fc = Ls.charat (0);
OPQ = ls.substring (1, 10);
Logger.info ("The first character that executes the return result of the Linux command is:" +FC);
Java Execute Linux command