Running a shell script from my plugin's directory

Answered

Hello there,

I want to run a shell script from my plugin's directory. 

Inside the resources directory, I've created another directory named "scripts" and have a script inside it named (let's say) script.sh

I tried to execute this script using Runtime.getRuntime().exec("sh script.sh") but it gave me an error :

Caused by: java.security.PrivilegedActionException: java.io.IOException: Cannot run program "sh script.sh": error=2, No such file or directory

 

I guess it's not able to find the shell script. Is there any way I can run the script in the plugin's directory? I don't want to ask the plugin's user to copy my script in his directory for it to work. It should work out of the box!

 

Any help would be really appreciated :)

Thanks in advance!

0
6 comments

Jain,

you can't run your bundled script this way, because it is not accessible via the filesystem - it's bundled within the plugin's artifact.

Even if - you'll need to provide a full path to the file, not just sh script.sh.

I'd suggest you load the script's content and run it as a command

1

Jakub Chrzanowski

I am trying to run a CURL request. But it just doesn't seem to work using Runtime.getRuntime().exec()

I even posted a question on this forum as well as stack overflow: https://stackoverflow.com/questions/61030427/curl-post-request-in-kotlin-using-runtime-getruntime-exec-errors-with-data

So, I had to resort to write a script to make the curl request.

Also, how to provide the full path to a plugin artifact? Do we have any API to know the exact location of the plugin (and eventually it's artifact) in the user's machine?

0

Can I ask why you want to go with CURL instead of making a request right from the IDE?

0

Jakub Chrzanowski

Couldn't find a good Kotlin library for networking. Hence, thought it'd be easier to make API call via CURL. Didn't want to go all the way back to HttpUrlConnection.

I'm just starting with Plugin Development, and this would be my first plugin. Could you suggest something else?

0

What if the user will have no curl? Will Windows be appropriately handled?

Have you checked ktor?

0

Yeah. Hadn't thought about that !

Will check out ktor now. I did have a look at it earlier but was hooked on making a simpler CURL request.

Thank you so much :) Would've totally missed the windows compatibility thing.

0

Please sign in to leave a comment.