windows - How can I pass batch arguments with dots into a powershell script? -
I have a batch script that will be run by an external process that is not in my control arguments for external process batch script Can provide a variable amount of Then I want to pass these variables in PowerShell Script. The problem is that some of these variables appear:
-Dfoo.bar = baz
For any reason the powers are broken into two arguments on the command line, I just arg You can add quotation around and call it a day. But how do I pass batches like this? This is my script:
@echo off SET CMD = C: \ Scripts \ foo.ps1 PowerShell.Exe -Command "% CMD%"% *
< P> I saw that this question is very similar. Here he is avoiding the $ character I tried to do something similar to dot and / or dash four, but there is no luck. Anyone have any ideas?
Something like this can work:
@hoho of set "CMD = C: \ script \ foo.ps1" set "ARGS =% *" set "ARGS =% ARGS: = ''%" PowerShell Ex-Commands "% CMD%" '% ARGS%'
Display:
C: \> Type test.cmd @echo off set "CMD = C: \ test Ps1" set "args =% *" set "args =% args: = ''%" PowerHale-Commands "% CMD%" '% args%' C: \ > type test.ps1 $ args | % {$ _} C: \> test.cmd -Dfoo.bar = baz-something -Dfoo.bar = baz-something
single around With quote debate, PowerShell is making flirtatious things with that argument, by replacing the space in the logic code with ''
, you put single quotas after a logic and before the next one, Add unavailable quotation before "external" single quote first and last argument.
c: \> type test2.cmd @echo off set "args =% *" echo% args% set "args =% args: = '' % "Echo% args% echo '% args%' c: \> test2.cmd -Dfoo.bar = baz - something -Dfoo.bar = baz-something -Dfoo.bar = baz '' -something '-Dfoo.bar = baz' '-something'
Comments
Post a Comment