I’m trying to run a simple bash script (I’ve run chmod +x on the file) via gradle: ```#!/bin/bash ec...
g
I’m trying to run a simple bash script (I’ve run chmod +x on the file) via gradle:
Copy code
#!/bin/bash
echo "> Yay!"
task:
Copy code
tasks.register<Exec>("runBashScript") {
    commandLine("./script.sh")
}
But I’m always getting:
Copy code
Execution failed for task ':runBashScript'.
> A problem occurred starting process 'command './script.sh''
I’m lost 😕
not kotlin but kotlin colored 1
c
This out of topic for this channel, see the dedicated Gradle Slack invite in the channel description. I recommend running your task with
--info
to get an idea for what is actually being executed, in the past I've had similar issues when the working directory was not what I was expecting
👍 1
v
That's not so much a question about working directory. Shell scripts are simply not executable by the operating system. That you can execute them manually from commandline is a feature of the shell you are using. So you proabably need to call
bash
or similar with the script as argument. Besides that the question is not kotlin but kotlin colored of course, yeah 🙂
g
Thanks I’m going to ask in Gradle slack 🙂 But i’ve tested also with: “bash” and I was having the same problem.
y
Isn't #! Part of the Linux process spec, not a bash thing? https://tldp.org/LDP/tlk/kernel/processes.html
v
A quote from that page:
Script files have to be recognized and the appropriate interpreter run to handle them; for example /bin/sh interprets shell scripts.
🤷‍♂️
y
I've never had a problem using process exec to run script files, so I was sure it is supported.
v
Maybe it is and I remembered wrongly. Or it is just more portable, as with
bash -c
it also works on windows and directly probably won't.
y
I think you want that explicit bash -c when running it depends on things like your profile files executed. But not certain.