public static List < String > captureOutAndError ( List < String > setup , List < String > cmd , File stdoutFilename , File stderrFilename , long tailLength , boolean useSetsid ) throws IOException { List < String > result = new ArrayList < String > ( 3 ) ; result . add ( bashCommand ) ; result . add ( "-c" ) ; String mergedCmd = buildCommandLine ( setup , cmd , stdoutFilename , stderrFilename , tailLength , useSetsid ) ; result . add ( mergedCmd . toString ( ) ) ; return result ; }
Wrap a command in a shell to capture stdout and stderr to files . Setup commands such as setting memory limit can be passed which will be executed before exec . If the tailLength is 0 the entire output will be saved .