mirror of https://github.com/FongMi/TV.git
parent
d4a8bceda6
commit
0cb8a29d03
@ -1,26 +1,13 @@ |
|||||||
package com.github.catvod.utils; |
package com.github.catvod.utils; |
||||||
|
|
||||||
import java.io.DataOutputStream; |
|
||||||
|
|
||||||
public class Shell { |
public class Shell { |
||||||
|
|
||||||
private static final String COMMAND_SH = "sh"; |
|
||||||
private static final String COMMAND_EXIT = "exit\n"; |
|
||||||
private static final String COMMAND_LINE_END = "\n"; |
|
||||||
|
|
||||||
public static void exec(String command) { |
public static void exec(String command) { |
||||||
try { |
try { |
||||||
Process p = Runtime.getRuntime().exec(COMMAND_SH); |
int code = Runtime.getRuntime().exec(command).waitFor(); |
||||||
DataOutputStream dos = new DataOutputStream(p.getOutputStream()); |
if (code != 0) throw new RuntimeException("Shell command failed with exit code " + code); |
||||||
dos.write(command.getBytes()); |
|
||||||
dos.writeBytes(COMMAND_LINE_END); |
|
||||||
dos.writeBytes(COMMAND_EXIT); |
|
||||||
dos.flush(); |
|
||||||
dos.close(); |
|
||||||
p.waitFor(); |
|
||||||
p.destroy(); |
|
||||||
} catch (Exception e) { |
} catch (Exception e) { |
||||||
e.printStackTrace(); |
e.printStackTrace(); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
Loading…
Reference in new issue