Gradle command line


I’m trying to run a shell script with gradle. I currently have something like this

def test = project.tasks.create("test", Exec) {
    commandLine 'bash', '-c', 'bash C:/my file dir/'

The problem is that I cannot run this script because i have spaces in my dir name. I have tried everything e.g:

commandLine 'bash', '-c', 'bash C:/my file dir/'.tokenize() 
commandLine 'bash', '-c', ['bash', 'C:/my file dir/']
commandLine 'bash', '-c', new StringBuilder().append('bash').append('C:/my file dir/')
commandLine 'bash', '-c', 'bash "C:/my file dir/"'
File dir = file('C:/my file dir/')
commandLine 'bash', '-c', 'bash ' + dir.getAbsolutePath();

Im using windows7 64bit and if I use a path without spaces the script runs perfectly, therefore the only issue as I can see is how gradle handles spaces.

You’ll probably have to escape them like this "C:/my\\ file\\ dir/"

I forgot to mention that I also tried this and it doesn’t work. This is causing way too much problem for a small thing like this :confused:

Perhaps enclosing that argument in quotes '"C:/my\\ file\\ dir/"'.

Is there any reason for invoking bash twice? Why not just

commandLine 'bash', 'c:/my file dir/'

Hm sorry but it doesn’t work, thanks for your help.

Did you try:

commandLine ‘bash’, ‘-c’, ‘“bash C:/my\ file dir/”’

i.e. enclose the whole 2nd bash command in double quotes (escaping spaces with \) and then wrap it in single quotes, as gradle argument?