0

I want to call a batch file with powershell, like this:

$databaseUrl = "jdbc:sqlserver://$($databaseConfig.Server):$($databaseConfig.Port);databaseName=$($databaseConfig.Name)"

./database/liquibase/liquibase.bat --url=$databaseUrl

My problem is that the = is replaced with a whitespace, leaving only --url as the first parameter. I try putting it in quotes:

.\database\liquibase\liquibase.bat "--url=$databaseUrl"

...with the same result. I read that I can use backtick to escape characters:

.\database\liquibase\liquibase.bat "--url`=$databaseUrl"

...but the equals sign still disappears. I have also tried using --% to prevent any formatting from happening:

.\database\liquibase\liquibase.bat --% "--url=$databaseUrl"

but then the variable $databaseUrl is interpreted verbatim.

Any help on how to pass the argument, unformatted, but with variables expanded would be greatly appreciated.

2
  • Your best option would be to allow the --url:<value> syntax as well, if you have the batch file under your control. There are a couple of questions, and comments, like this one that explain the details of the issue. Commented Sep 22, 2015 at 13:50
  • It's too long for a comment, but this is the important part: java -cp "%CP%" %JAVA_OPTS% liquibase.integration.commandline.Main %CMD_LINE_ARGS%. When I start the java command from the powershell script, the formatting of the parameters seem to work. I think that is my best bet. Commented Sep 22, 2015 at 15:01

1 Answer 1

0

maybe tricky, but as the escape operator --% allow environmnent variable expansion you could try this :

$env:databaseUrl ="jdbc:sqlserver://$($databaseConfig.Server):$($databaseConfig.Port)"
$env:db="$($databaseConfig.Name)"
.\database\liquibase\liquibase.bat --% "--url=%databaseUrl%;databasename=%db%"
Sign up to request clarification or add additional context in comments.

3 Comments

I have been testing with environment variables, but they are still causing problems. Running your example, the batch file gets this input: --url jdbc:sqlserver://TEST:1433 databaseName SomeDbName
tweak a bit more.... $env:url="jdbc:sqlserver://server:8080" ; $env:db="someDBName" ; \liquibase.bat --% "--url=%url%;databasename=%db%"
Now the imput parameter looks like this "--url=jdbc:sqlserver://server:8080;databasename=someDBName". That seems fine, but when the parameter is used to start a java program, it doesn't work. Probably because it is all in a string. Like I commented above, if I start the java process directly from powershell, the parameters are fine. I think I'll go for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.