How To Redirect Output From Java Callout Runtime.exec() To A File On Unix Without Using Process.getInputStream()
(Doc ID 430403.1)
Last updated on FEBRUARY 03, 2022
Applies to:
Oracle Database - Enterprise Edition - Version 10.2.0.2 and laterInformation in this document applies to any platform.
Goal
Having some Java code to run an external process like
public class OSCommand{
public static String Run(String Command){
try{
Runtime.getRuntime().exec(Command);
return("0");
}
catch (Exception e){
System.out.println("Error running command: " + Command +
"\n" + e.getMessage());
return(e.getMessage());
}
}
}
we want to redirect the output of this process to a file. However, we do not want to have to deal with Java's Process.getInputStream() and Process.getErrorStream() because we do not want to do so much Java coding.
And calling that method with Unix-like input redirection like
OSCommand.Run ("ls -alR >/tmp/allFiles.lst")
cannot work because the Run method only calls the ls command and nothing that would take care of the output redirection.
Solution
To view full details, sign in with your My Oracle Support account. |
|
Don't have a My Oracle Support account? Click to get started! |
In this Document
Goal |
Solution |
Considerations |
An Elegant but Platform Specific Approach |
Inside and Outside of the OracleJVM |
References |