mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 13:16:44 +00:00
read and throw hwi error stream if stdout empty
This commit is contained in:
parent
e3799cd0a8
commit
0cc9ddba05
1 changed files with 20 additions and 6 deletions
|
@ -290,9 +290,7 @@ public class Hwi {
|
||||||
try {
|
try {
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||||
process = processBuilder.start();
|
process = processBuilder.start();
|
||||||
try(InputStreamReader reader = new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)) {
|
return getProcessOutput(process);
|
||||||
return CharStreams.toString(reader);
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
deleteExtractionOnFailure(process, start);
|
deleteExtractionOnFailure(process, start);
|
||||||
}
|
}
|
||||||
|
@ -318,14 +316,30 @@ public class Hwi {
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
try(InputStreamReader reader = new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)) {
|
return getProcessOutput(process);
|
||||||
return CharStreams.toString(reader);
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
deleteExtractionOnFailure(process, start);
|
deleteExtractionOnFailure(process, start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getProcessOutput(Process process) throws IOException {
|
||||||
|
String output;
|
||||||
|
try(InputStreamReader reader = new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)) {
|
||||||
|
output = CharStreams.toString(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(output.isEmpty() && process.getErrorStream() != null) {
|
||||||
|
try(InputStreamReader reader = new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8)) {
|
||||||
|
String errorOutput = CharStreams.toString(reader);
|
||||||
|
if(!errorOutput.isEmpty()) {
|
||||||
|
throw new IOException(errorOutput);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized File getHwiExecutable(Command command) {
|
private synchronized File getHwiExecutable(Command command) {
|
||||||
File hwiExecutable = Config.get().getHwi();
|
File hwiExecutable = Config.get().getHwi();
|
||||||
if(hwiExecutable != null && hwiExecutable.exists()) {
|
if(hwiExecutable != null && hwiExecutable.exists()) {
|
||||||
|
|
Loading…
Reference in a new issue