I'm just getting started using kscript, and I'm tr...
# scripting
h
I'm just getting started using kscript, and I'm trying to use
runCommand()
from kscript-tools. Anyone familiar with this? I've added the dependency to my script:
Copy code
@file:DependsOn("com.sealwu:kscript-tools:1.0.2")
and I've added a line to my script to test it:
Copy code
"ls".runCommand()
But when I run the script,
runCommand()
can't be found:
Copy code
error: unresolved reference: runCommand
If I run the script from IDEA using
Copy code
kscript --idea myscript.kts
it works fine. It's only when I run the script from the command line that it fails. Anyone have any idea what I'm doing wrong?
Here's the contents of my test script:
Copy code
#!/usr/bin/env kscript
@file:DependsOn("com.sealwu:kscript-tools:1.0.2")

"ls".runCommand()
Happens so often - just when I throw up my hands and ask for help, I find the answer to my own problem. Importing
runCommand
fixes the problem!
Copy code
#!/usr/bin/env kscript
@file:DependsOn("com.sealwu:kscript-tools:1.0.2")

import runCommand

"ls".runCommand()
Still not sure why it's necessary though. 🤷
b
runCommand is an extension function so as anything third-party in JVM it needs to be imported before use.