My Oracle Support Banner

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 and later
Information in this document applies to any platform.


Having some Java code to run an external process like

public class OSCommand{
public static String Run(String Command){
catch (Exception e){
System.out.println("Error running command: " + Command +
"\n" + 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.


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
 An Elegant but Platform Specific Approach
 Inside and Outside of the OracleJVM

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.