Redirecting stdout and stderr to OpenTAP log

Hi, when running a bash script on Linux (Ubuntu, for example), is it possible to redirect stdout and stderr to the default OpenTAP log? How would you suggest doing that?

-Nav

Hi Nav,

I’m not sure what you mean, but if you’re talking about running a bash script from plugin code, you can take a look at how the Run Program step does it: opentap/ProcessStep.cs at main · opentap/opentap · GitHub

You would need something like this

void RunScript()
{
    var process = new Process()
    {
        StartInfo =
        {
            FileName = "bash",
            Arguments = "my-script.sh",
            RedirectStandardError = true,
            RedirectStandardOutput = true,
        }
    };
    process.OutputDataReceived += (sender, e) => Log.Info(e.Data);
    process.ErrorDataReceived += (sender, e) => Log.Error(e.Data);
    process.WaitForExit();
}

Though I may be misunderstanding your use case.

1 Like

Thanks for the reply @alexander.larsen.
To clarify, I was looking for a way to route the Linux bash command output (e.g. echo and other commands that usually generate text on a console) to the OpenTAP log, both on the Log in the UI and the generated text log file.
It looks like ‘Run Program’ step already has an ‘Add to Log’ setting that routes the output. That will work for my purpose

1 Like