All Articles

Execute System Commands and Return Standard Output to Document Flow

The Program Command shape can execute system commands, but there is no output other than a notification of success or failure. Sometimes there might be a requirement where the standard output of the system command needs to be used to determine decisions within the process. The script below takes a message shape set with the script to be run before the Data Process shape. Each document needs to be a single command. Also, this script will only run on local atoms with lower security settings.

import java.util.Properties
import java.io.InputStream
import com.boomi.execution.ExecutionUtil
import java.util.stream.Collectors

for (int i = 0; i < dataContext.getDataCount(); i++) {
    InputStream is = dataContext.getStream(i)
    Properties props = dataContext.getProperties(i)

    String command = new BufferedReader(new InputStreamReader(is))
            .lines()
            .collect(Collectors.joining(System.lineSeparator()));
    Process process = Runtime.getRuntime().exec(command);

    dataContext.storeStream(process.getInputStream(), props)
}

Published Aug 21, 2021

Developing a better world.© All rights reserved.