Created
January 13, 2019 05:33
-
-
Save diaolizhi/c3202e81bfb7acfec00b6e4e57474f6a to your computer and use it in GitHub Desktop.
Java 执行 shell 脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ReloadSystem { | |
public static void reloadSystem() { | |
ProcessBuilder processBuilder = new ProcessBuilder(); | |
processBuilder.command("bash", "-c", "bash ~/tieba-demo/Tieba/reload.sh"); | |
try { | |
Process process = processBuilder.start(); | |
StringBuilder output = new StringBuilder(); | |
BufferedReader reader = new BufferedReader( | |
new InputStreamReader(process.getInputStream())); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
output.append(line + "\n"); | |
} | |
int exitVal = process.waitFor(); | |
if (exitVal == 0) { | |
System.out.println(output); | |
return; | |
} else { | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment