Я установил MySQL в контейнер Docker и попытался запустить этот код Java, чтобы получить некоторое значение переменной: < /p>
String[] cmd = new String[] {"docker", "exec", "my", "mysql", "-p123456", "-e", "select @@report_host\\G"};
Pair result = this.execForExitCode(cmd);
String[] lines = result.getRight().split("\n");
log.info("getDbReportHost:");
for (String line : lines) {
log.info(line);
}
< /code>
private Pair execForExitCode(String[] command) {
try {
Process process = new ProcessBuilder(command).inheritIO().start();
String rst = new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
return Pair.of(process.waitFor(), rst);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
< /code>
But got nothing.
Instead, if I run the command directly on the console:
docker exec -it my mysql -uroot -p123456 -e "select @@report_host\G"
< /code>
I get this output:
*************************** 1. row ***************************
@@report_host: 10.15.100.95
< /code>
And this is what I want.
So what's wrong with my Java code?
Подробнее здесь: https://stackoverflow.com/questions/795 ... md-in-java