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 JULY 16, 2019

Applies to:

Oracle Server - Enterprise Edition - Version: and later   [Release: 10.2 and later ]
Information in this document applies to any platform.
***Checked for relevance on 23-Feb-2010***


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

This document is being delivered to you via Oracle Support's Rapid Visibility (RaV) process and therefore has not been subject to an independent technical review.

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