I got a dump of the table by kicking the ShellScript on the server with an additional function I've never done it in Java, so I'll write it down I used this person as a reference Here, execute the ShellScript of RenumberData.sh in / home / dev / sample / work / sh /
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
yobidashi.java
CallProcess sh = new CallProcess();
sh.doBackupTable("RenumberData");
CallProcess
CallProcess.java
package mr.yappy;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import sample.core.log.Logger;
/**
*Shell script execution processing class
* @param shName Execution shell name
* @author yappy
* @version 1.0.0
*/
public class CallProcess {
private Logger log = Logger.getLogger("aaa");
public void doBackupTable(String shName) {
Process process = null;
InputStream inputS = null;
InputStreamReader isReader = null;
BufferedReader bReader = null;
String text = "";
try {
//Specify Path in the server
String shPath = "/home/dev/sample/work/sh/";
ProcessBuilder pb = new ProcessBuilder("sh", shPath + shName + ".sh");
// /home/dev/sample/work/sh/RenumberData.run sh
process = pb.start();
//inputS = process.getInputStream();
inputS = process.getErrorStream();
//isr = new InputStreamReader(inputS, "Shift-JIS");
isReader = new InputStreamReader(inputS, "UTF-8");
bReader = new BufferedReader(isReader);
StringBuilder builder = new StringBuilder();
String c = "";
while ((c = bReader.readLine()) != null) {
//Writing execution results
builder.append(c);
}
//Execution result
text = builder.toString();
//End
process.waitFor();
//Get processing status
int ret = process.exitValue();
if (ret == 0) {
//Successful completion
} else {
//Abnormal termination
log.error("error result : " + text);
}
} catch (IOException | InterruptedException e) {
log.error(e,e);
} finally {
//Various closes
if (process != null) {
process.destroy();
}
if (inputS != null) {
try {
inputS.close();
} catch (IOException e) {
log.error(e,e);
}
}
if (isReader != null) {
try {
isReader.close();
} catch (IOException e) {
log.error(e,e);
}
}
if (bReader != null) {
try {
bReader.close();
} catch (IOException e) {
log.error(e,e);
}
}
}
}
}
Recommended Posts