public boolean slurpOutput(FastPipedOutputStream stdout, FastPipedOutputStream stderr) throws IOException {
log.log(Level.FINE, "--> SlurpOutput");
ImmutableMap<String, FastPipedOutputStream> streams = ImmutableMap.of("stdout", stdout, "stderr", stderr);
Document request = factory.newGetOutputRequest(shellId, commandId).build();
Document response = sendRequest(request);
XPath xpath = DocumentHelper.createXPath("//" + Namespaces.NS_WIN_SHELL.getPrefix() + ":Stream");
namespaceContext = new SimpleNamespaceContext();
namespaceContext.addNamespace(Namespaces.NS_WIN_SHELL.getPrefix(), Namespaces.NS_WIN_SHELL.getURI());
xpath.setNamespaceContext(namespaceContext);
Base64 base64 = new Base64();
for (Element e : (List<Element>) xpath.selectNodes(response)) {
FastPipedOutputStream stream = streams.get(e.attribute("Name").getText().toLowerCase());
final byte[] decode = base64.decode(e.getText());
log.log(Level.FINE, "piping " + decode.length + " bytes from "
+ e.attribute("Name").getText().toLowerCase());
stream.write(decode);
}
XPath done = DocumentHelper.createXPath("//*[@State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done']");
done.setNamespaceContext(namespaceContext);
if (Iterables.isEmpty(done.selectNodes(response))) {
log.log(Level.FINE, "keep going baby!");
return true;
} else {
exitCode = Integer.parseInt(first(response, "//" + Namespaces.NS_WIN_SHELL.getPrefix() + ":ExitCode"));
log.log(Level.FINE, "no more output - command is now done - exit code: " + exitCode);
}
return false;
}