1

My shell script file is available under src/test/java/testdata folder.

I tried below code but it did not work.

karate.fork({ args: ['cd', 'D:/Users/shr/Desktop/18april/project/src/test/java/data/testdata;', 'bash', 'loadOptions.sh'] })
karate.fork({ args: [ 'bash', 'classpath:testdata/loadOptions.sh'] })

Got below error.

22:12:12.522 [1686933732519] DEBUG com.intuit.karate - command: [cd, D:/Users/shr/Desktop/18april/project/src/test/java/data/testdata;, bash, loadOptions.sh], working dir: null

22:12:12.565 [1686933732519] ERROR com.intuit.karate.shell.Command - command error: [cd, D:/Users/shr/Desktop/18april/project/src/test/java/data/testdata;, bash, loadOptions.sh] - Cannot run program "cd": CreateProcess error=2, The system cannot find the file specified

James Z
  • 12,209
  • 10
  • 24
  • 44
Shreyansh Jain
  • 498
  • 4
  • 7
  • keep trying. has to be some path issue. also read: https://stackoverflow.com/a/62911366/143475 – Peter Thomas Jun 16 '23 at 20:03
  • 1
    Finally, I managed to make it work and below is the working code. Feature: Executing Shell script Feature Background: * def command = """ function(line,dirPath) { karate.exec({ workingDir: dirPath, line: line, useShell: true}); } """ Scenario: Executing Shell script * def file = karate.toJavaFile('../features') * def path = file.getPath() * print "path ",path * command('sample.sh',path) – Shreyansh Jain Jun 17 '23 at 12:35

0 Answers0