How to call a batch having carets ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
colargol
Posts: 49
Joined: 28 Sep 2011 13:23
Location: france

How to call a batch having carets ?

#1 Post by colargol » 19 Nov 2011 10:05

Hello!
How to call .bat file having carets please?

Code: Select all

call "a ^ b.bat"

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: How to call a batch having carets ?

#2 Post by Ed Dyreen » 19 Nov 2011 10:12

'

Code: Select all

call "a ^^ b.bat"

colargol
Posts: 49
Joined: 28 Sep 2011 13:23
Location: france

Re: How to call a batch having carets ?

#3 Post by colargol » 19 Nov 2011 10:22

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:

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: How to call a batch having carets ?

#4 Post by Ed Dyreen » 19 Nov 2011 10:27

'
really ?, hmmm :roll: no time to test sorry

colargol
Posts: 49
Joined: 28 Sep 2011 13:23
Location: france

Re: How to call a batch having carets ?

#5 Post by colargol » 19 Nov 2011 11:27

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' !

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: How to call a batch having carets ?

#6 Post by jeb » 19 Nov 2011 15:30

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

colargol
Posts: 49
Joined: 28 Sep 2011 13:23
Location: france

Re: How to call a batch having carets ?

#7 Post by colargol » 19 Nov 2011 16:05

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!

colargol
Posts: 49
Joined: 28 Sep 2011 13:23
Location: france

Re: How to call a batch having carets ?

#8 Post by colargol » 19 Nov 2011 16:40

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: )

Post Reply