I try to create a simple Gradle task to execute an sql query. The command I try to execute is:
UPDATE user_account SET user_password = 'xyz'
The complete command line looks like this:
"c:\Program Files\MariaDB 10.3\bin\mysql.exe" --user=dbUser --password=dbPass-D dbName -e "UPDATE user_account SET user_password = 'xyz'"
This command works fine from the command line. However it doesn't work from a Gradle Exec task:
task updatePasswords(type:Exec) {
def sql = "UPDATE user_account SET user_password = 'xyz'"
def myCmd = '"' + dbSqlExe + '" --user=' + dbUser + ' --password=' + dbPass + ' -D ' + dbDb + ' -e "' + sql + '"'
println 'Update cmd: ' + myCmd
commandLine 'cmd', '/c', myCmd
ignoreExitValue = true
}
Where
def dbSqlExe = "c:\\Program Files\\MariaDB 10.3\\bin\\mysql.exe"
This task reports an error:
'c:\Program' is not recognized as an internal or external command, operable program or batch file.
If I remove the double quotes around the sql query then mysql.exe will be found, but the command is not valid any more as mysql requires the double quotes around the SQL query.
I have tried the solution in this thread: gradle: Execute task "type:Exec" with many arguments with spaces without success.
Any tip how should I format my task?