https://kotlinlang.org logo
#gradle
Title
g

Guilherme Delgado

09/08/2023, 10:21 AM
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

CLOVIS

09/08/2023, 10:23 AM
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

Vampire

09/08/2023, 10:40 AM
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

Guilherme Delgado

09/08/2023, 10:42 AM
Thanks I’m going to ask in Gradle slack 🙂 But i’ve tested also with: “bash” and I was having the same problem.
y

yschimke

09/08/2023, 4:45 PM
Isn't #! Part of the Linux process spec, not a bash thing? https://tldp.org/LDP/tlk/kernel/processes.html
v

Vampire

09/08/2023, 9:15 PM
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

yschimke

09/09/2023, 6:11 AM
I've never had a problem using process exec to run script files, so I was sure it is supported.
v

Vampire

09/09/2023, 10:18 AM
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

yschimke

09/09/2023, 10:54 AM
I think you want that explicit bash -c when running it depends on things like your profile files executed. But not certain.
2 Views