Page 1 of 1

How to call a batch having carets ?

Posted: 19 Nov 2011 10:05
by colargol
Hello!
How to call .bat file having carets please?

Code: Select all

call "a ^ b.bat"

Re: How to call a batch having carets ?

Posted: 19 Nov 2011 10:12
by Ed Dyreen
'

Code: Select all

call "a ^^ b.bat"

Re: How to call a batch having carets ?

Posted: 19 Nov 2011 10:22
by colargol
Ed Dyreen wrote:

Code: Select all

call "a ^^ b.bat"
Hum... this is trying to call "a ^^^^ b.bat", as call command escapes carets :shock:

Re: How to call a batch having carets ?

Posted: 19 Nov 2011 10:27
by Ed Dyreen
'
really ?, hmmm :roll: no time to test sorry

Re: How to call a batch having carets ?

Posted: 19 Nov 2011 11:27
by colargol
I think I've found: :D

Code: Select all

set "bat_file=a ^ b.bat"
call "%bat_file:^="^^"%"

:: or

set "bat_file2=%bat_file:^="^^^^"%"
call "%bat_file2%"
call seems to escape ^ only if they are surrounded by quotes.
thank anyway Ed' !

Re: How to call a batch having carets ?

Posted: 19 Nov 2011 15:30
by jeb
Ok, you create solutions, but IMHO it's a bit too complex.

Code: Select all

call "a "^^" b.bat"


or this one for witout any modifcations in the filename

Code: Select all

set "file=a ^ b.bat"
call "%%file%%"


Why this works :?: And why the simple one fails :?:

colargol wrote:call seems to escape ^ only if they are surrounded by quotes.


Seems so, but it's not correct. :wink:
A CALL doubles all carets, inside of quotes and also outside.
But after this parser phase the percent expansion phase runs and the the special character phase.
In this phase the caret works as escape character, it escapes the next character, itself will be removed,
but only outside of quotes.

Example with the relevant parser phases

Code: Select all

CALL echo caret^^ "^^"

Phase2 Special characters
-> CALL echo caret^ "^"
....
Phase8 Call Restart parser, doubling all carets
-> echo caret^^ "^^"
...
Phase2 Special characters
-> echo caret^ "^^"

hope it helps
jeb

Re: How to call a batch having carets ?

Posted: 19 Nov 2011 16:05
by colargol
I think I love this forum! :D

jeb wrote:hope it helps
Of course it helps!
worked perfectly with my test file :D

Code: Select all

escape tests a%b&c^d!é'f)g(h=i`j~k%%l&&m^^n!!o.bat

another advantage of your technic: I don't have to escape % before the call as I was doing till now

Code: Select all

set "file=!file:%%=%%%%!"


Many thanks!

Re: How to call a batch having carets ?

Posted: 19 Nov 2011 16:40
by colargol
And of course, this is the same for arguments:

Code: Select all

set "file=a ^ b.bat"
set "arg1=this ^ works"
set "arg2=perfectly ^^"

call "%%file%%" "%%arg1%%" "%%arg2%%"

(except if args have one " ... :shock: )