Interesting, didn’t knew that … long time since I was using Java/Groovy.
Following your approach, I made few changes to make it simpler.
I made a small script in my project folder which which just produce a single line of output:
[ibus@localhost test]$ cat myscript.sh
#!/bin/bash
echo 'some text here'
Note1: I am using a shebang, as any sane shell script should have.
Note2: My shebang is enforcing the bash shell.
For a generic (portable script) one may want to use:
#!/usr/bin/env sh
Made it executable:
chmod +x ./myscript.sh
With your approach, I just changed this line, the rest is the same (note that I am not using sh -c
):
process = Runtime.getRuntime().exec('./myscript.sh')
Output:
2022-03-06 12:02:11.643 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2022-03-06 12:02:11.646 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/SH test
before test case
2022-03-06 12:02:11.930 DEBUG testcase.SH test - 1: process = getRuntime().exec("./myscript.sh")
2022-03-06 12:02:11.940 DEBUG testcase.SH test - 2: stdout = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream()))
2022-03-06 12:02:11.957 DEBUG testcase.SH test - 3: line = <not implemented yet for class: org.codehaus.groovy.ast.expr.EmptyExpression>
2022-03-06 12:02:11.958 DEBUG testcase.SH test - 4: while (line = stdout.readLine() != null)
2022-03-06 12:02:11.960 DEBUG testcase.SH test - 1: println(line)
some text here
2022-03-06 12:02:11.972 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/SH test