Search code examples
linuxkarateintuit-partner-platform

Executing multiple linux commands using karate.fork()


Is it possible to add multiple commands using karate.fork()? I tried adding the commands using ; or && separation but the second command doesn't seem to be getting executed.

I am trying to cd to a particular directory before executing bash on a shell script.

* def command =
"""
function(line) {
    var proc = karate.fork({ redirectErrorStream: false, useShell: true, line: line });
    proc.waitSync();
    karate.set('sysOut', proc.sysOut);
    karate.set('sysErr', proc.sysErr);
    karate.set('exitCode', proc.exitCode);
}
"""
* call command('cd ../testDirectory ; bash example.sh')

Solution

  • Note that instead of line - args as an array of command line arguments is supported, so try that as well - e.g. something like:

    karate.fork({ args: ['cd', 'foo;', 'bash', 'example.sh'] })
    

    But yes this may need some investigation. You can always try to have all the commands in a single batch file which should work.

    Would be good if you can try the 1.0 RC since some improvements may have been added: https://github.com/intuit/karate/wiki/1.0-upgrade-guide