0

When I call following command from the command line, everything works well. But when I put it in a .bat file and call that file, I get the syntax error saying that I'm missing a closing ' at the end of the command.

powershell -command "& 'C:\Program Files\TortoiseSVN\bin\svn.exe' status  | ? { $_ -Match '^!\s+(.*)' } | % { & 'C:\Program Files\TortoiseSVN\bin\svn.exe' rm $Matches[1] }"

A strange thing that happens when I call it from .bat is that command gets mysteriously changed. This is the output of the .bat file:

C:\workspace>powershell -command "& 'C:\Program Files\TortoiseSVN\bin\svn.exe' status  | ? { $
_ -Match '^!\s+(.*)' } | \Program Files\TortoiseSVN\bin\svn.exe' rm $Matches[1] }"
The string is missing the terminator: '.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

I'm 100% sure that the content of the .bat file and the command I run manually are the same and that editor (Notepad++) does not perform a stupid thing like breaking the command in two lines.

What am I doing wrong?

1
  • } | \Program Files\T in that section you are missing a single quote. Should be } | '\Program Files\T or } | 'C:\Program Files\T. The code, in your examples, differs because of that. Commented Aug 18, 2014 at 16:32

1 Answer 1

2

Character % anywhere in a string must be escaped with one more % in a batch file to be interpreted as literal character.

powershell -command "& 'C:\Program Files\TortoiseSVN\bin\svn.exe' status  | ? { $_ -Match '^!\s+(.*)' } | %% { & 'C:\Program Files\TortoiseSVN\bin\svn.exe' rm $Matches[1] }"

works in a batch file. Enter in a command prompt window help for or for /? and you can read about this requirement for escaping % on first help page output.

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

1 Comment

I was trying literally every combination of escaping for " and ' and \, but it haven't occurred to me that % requires escaping. Thanks a lot.

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.