1

I want to execute a python script which is located either:

  1. On my Local System or,
  2. Within the Karate project itself

My question is how to specify the paths of the above scripts location into karate.exec() command. I Tried giving the path but while executing it says working directory: null and python: can't open file + No such file or directory

Thonas1601
  • 1,347
  • 2
  • 9
  • 11

1 Answers1

0

The karate.exec() also takes a JSON argument where you can provide a workingDir. For example, I just tried this and it worked:

* def result = karate.exec({ args:['./netbeans'], workingDir: '/Users/peter/dev/netbeans/bin' })  

Note that I am on a Mac, so you can adjust directory and executable paths accordingly.

You can refer this other answer for more details and tips: https://stackoverflow.com/a/62911366/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    ok @Peter Thomas so will it for python as well? like karate.exec({ agrs:['python'],workingDir..... Also how to specify the path if its in karate project itself but in a separate folder – Thonas1601 Feb 09 '23 at 18:29
  • @Thonas1601 it should. relative paths should work, so you can experiment. I'm sure you can figure out a way to use variables (see other answer and the links) to dynamically form the working directory path etc. – Peter Thomas Feb 09 '23 at 18:34
  • ok @peter thomas i will try. Just one last thing for the files stores within karate can we give the path as classpath:com.... etc – Thonas1601 Feb 09 '23 at 18:40
  • Sorry @Peter Thomas. This did not worked. Neither the absolute path thing, Nor the json arguement with working directory. Tried with both local path and the file stored in Karate. It always says system cannot find the path specified. I even tried java.nio.file.Path to get the absolute path, but no luck. – Thonas1601 Feb 10 '23 at 07:40
  • @Thonas1601 sorry I give up. try to take the help of someone is all I can suggest. all the best – Peter Thomas Feb 10 '23 at 08:29