How to run shell tools from kotlin scrip

344 views Asked by At

I am trying to rewrite several sh-scripts into kotlin scripts. How can I run shell commands or execute binaries accessible in the PATH variable from a kotlin script?

1

There are 1 answers

0
jactor-rises On BEST ANSWER

A shell script is using the JVM (java virtual machine) to execute. Which means you can access the inner workings of this by using Runtime.getRuntime().

The most notable af the return is the exec-method

This class has been present since java version 1.0, but here is the javadocs for java 11: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Runtime.html