I'm trying to start a process in Java, which runs the following command (taken from this StackOverflow answer):
osascript -e 'the clipboard as «class HTML»' | perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))'
Here is my code:
public class ClipboardService {
public String getClipboardContents() {
try {
List<String> result;
List<Process> processes = ProcessBuilder.startPipeline(List.of(
new ProcessBuilder("osascript", "-e", "'the clipboard as «class HTML»'")
.inheritIO().redirectOutput(ProcessBuilder.Redirect.PIPE),
new ProcessBuilder("perl", "-ne", "'print chr foreach unpack(\"C*\",pack(\"H*\",substr($_,11,-3)))'")
.redirectError(ProcessBuilder.Redirect.INHERIT)
));
String res = new String(processes.get(processes.size() - 1).getInputStream().readAllBytes());
return res;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
I noticed that this method returned nothing, why? How to make it work?