I have this code enclosed within a method, which when I call through the main method, runs absolutely fine, and downloads for me the required file via wget. I can see the file in my project directory.
At the same time when I expose this method behind a rest svc, which passes the required url to the method, it does not appear to download files, although it passes through the code. (Checked in debugger mode). Does it mean, its trying to download it elsewhere or the ProcessBuilder exposed behind rest svc is a problem here?
Runtime rt = Runtime.getRuntime();
ProcessBuilder pb;
int exitVal = 0;
try {
pb = new ProcessBuilder("wget", "-O", "myFile.csv",myFileUrl);
pb.redirectErrorStream(true);
Process downloadFirst = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(downloadFirst.getInputStream()));
while (reader.readLine() != null) {}
exitVal = downloadFirst.waitFor();
LOG.info("Downloaded my file with exitValue:" + exitVal);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
As stated by @MrSmith42, it worked if I specify full path when calling from the rest service.