0

I am writing a bat file to automate the process of the below Codeception command.

php vendor/bin/codecept run tests/acceptance/SigninCest.php:^anonymousLogin$

The problem is that I cannot output the ^ character for example:

set functionNamePrefix=^^
set output=php vendor/bin/codecept run tests/acceptance/SigninCest.php:
set functionName=anonymousLogin
set functionNamePostFix=$
set command=%output%%functionNamePrefix%%functionName%%functionNamePostFix%

the $ symbol is correctly displayed but the ^ is not.

Any advice? Thanks

0

2 Answers 2

1

Enclose the variable in quotes:

set "functionNamePrefix=^^"

Now the variable %functionNamePrefix% will contain ^.

Sign up to request clarification or add additional context in comments.

Comments

1

Special characters such as the %|^ are seen as operators to cmd.

When you set functionNamePrefix=^^ and try to echo it, you effectively allow cmd to utilize the special character. Therefore, echo %functionNamePrefix% will give the more prompt, as cmd is expecting the next input line because of the ^.

When however you double quote a string, you are excluding the character in the current cmd run. It is however also recommended to double quote strings when using set to ensure you eliminate unwanted whitespace. For instance:

set var=value

Note the accidental space after value, this space will form part of the value as long as it exists, so enclose everything in double quotes to play safe and to ensure the special characters are not becoming functions in the current batch run.

set "functionNamePrefix=^^"
set "output=php vendor/bin/codecept run tests/acceptance/SigninCest.php:"
set "functionName=anonymousLogin"
set "functionNamePostFix=$"
set "command=%output%%functionNamePrefix%%functionName%%functionNamePostFix%"

1 Comment

Thanks for explaining my answer by posting this helpful answer, upvoted

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.