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 05, 2017

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.


Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms