1. Obtain the system type. Different systems have different file segmentation symbols.
Public static Boolean islinux (){
String OS = system. getproperty ("OS. Name"). tolowercase ();
If (OS. indexof ("Windows")>-1 ){
Return false;
}
Else {
Return true;
}
}
2. generate different commands based on different systems:
// Table name
String DBS = "Action ddinfo device devicealarm deviceinfo devicelog ";
LIST command = new arraylist ();
If (islinux ){
Command. Add (exec_path + "mysqldump ");
Command. Add ("-- opt ");
Command. Add ("-- user = root ");
Command. Add ("-- lock-all-tables = true ");
Command. Add ("-- result-file =" + dumpedfilepath + file. Separator + server_backup_ SQL _file );
Command. Add ("orca ");
String [] STR = DBs. Split ("");
For (INT I = 0; I <Str. length; I ++)
Command. Add (STR [I]);
}
Else {
Command. Add ("\" "+ exec_path +" mysqldump \ ""); // is this work?
Command. Add ("-- opt ");
Command. Add ("-- user = root ");
Command. Add ("-- lock-all-tables = true ");
Command. Add ("-- result-file =" + dumpedfilepath + file. Separator + server_backup_ SQL _file );
Command. Add ("orca ");
String [] STR = DBs. Split ("");
For (INT I = 0; I <Str. length; I ++)
Command. Add (STR [I]);
3. Run the command
Get Runtime
Private runtime cmd = runtime. getruntime ();
PROCESS p = cmd.exe C (string []) command. toarray (New String [0]), null );
String line;
Bufferedreader BR = new bufferedreader (New inputstreamreader (P. geterrorstream ()));
While (line = Br. Readline ())! = NULL)
Log. Error ("<" + line );
Process is used to display error information