5

Could you please advise how to fix command below, which removes unversioned items from svn

rem @echo off
for /f "tokens=2*" %%i in ('"c:\Program Files\TortoiseSVN\bin\svn.exe" status --no-ignore ^| find "?"') do echo %%i

variant below without path works:

rem @echo off
for /f "tokens=2*" %%i in ('svn.exe status --no-ignore ^| find "?"') do echo %%i

but i need to pass entire path with svn.exe. In this case it outputs C:\Program is not a valid program

Ben
  • 8,725
  • 1
  • 30
  • 48
user1266063
  • 75
  • 2
  • 7

3 Answers3

5

try with this:

   for /f "usebackq tokens=2*" %%i in (`"c:\Program Files\TortoiseSVN\bin\svn.exe" status --no-ignore ^| find "?"`) do echo %%i
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • Thanks. But it still outputs C:\Program is not a valid program – user1266063 Aug 01 '12 at 08:30
  • sorry it outputs: Files\TortoiseSVN\bin\svn.exe" – user1266063 Aug 01 '12 at 08:31
  • and what about : for /f "usebackq tokens=2*" %%i in (`'"c:\Program Files\TortoiseSVN\bin\svn.exe"' status --no-ignore ^| find "?"`) do echo %%i (use ' toghether with "). YOu can also save the path to the executable to a variable and substitute it in the for loop – npocmaka Aug 01 '12 at 08:31
  • it doesn't actually executes "c:\Program Files\TortoiseSVN\bin\svn.exe" status --no-ignore, it just outputs the part after space... – user1266063 Aug 01 '12 at 08:32
  • 1
    short paths are option too.try to replase "program files" with PROGRA~1 – npocmaka Aug 01 '12 at 08:36
  • thanks for variable, but things doesn't change for some reason. there're soooooo black magic. – user1266063 Aug 01 '12 at 08:37
  • 1
    Thanks. Your nindzutsu helped. for /f "tokens=2*" %%i in ('c:\Progra~1\TortoiseSVN\bin\svn.exe status --no-ignore ^| find "?"') do echo %%i – user1266063 Aug 01 '12 at 08:42
  • One more hint: Are you sure you used a back quotes with usebackq parameter.Symbols are different ` (under the escape) and ' .usebackq is created especially for double quotes inside the for loop text.For more info check this: http://ss64.com/nt/for_f.html – npocmaka Aug 01 '12 at 08:42
1

When I ran into this problem, I tried using "usebackq" as suggested in the Windows command reference[1]:

Specifies to execute a back-quoted string as a command, and a single-quoted string as a literal string command. Also, allows file names in Set to be enclosed in quotation marks.

I found that this still gave an error about C:\Program not being executable.

Then I remembered, that Windows cmd.exe has really weird quoting rules, where if the first and last character in an executed string are quotes, they will be stripped[2].

So I tried this, and it worked for me:

for /F usebackq %%d in (`""path to command" arg arg "quoted arg""`) do @echo %%d

[1] http://technet.microsoft.com/en-us/library/cc754900.aspx

[2] http://technet.microsoft.com/en-us/library/cc771320.aspx

Ben
  • 8,725
  • 1
  • 30
  • 48
1

Going off of Ben's answer above (https://stackoverflow.com/a/25084830/2630028), the below example worked for me:

for /f "usebackq delims=" %%j in (`^""C:\Perl64\bin\perl" -e "print(qq(foo))"^"`) do (
    echo LINE: %%j 
)

It seems like I have to escape the outer quotes with ^ (https://ss64.com/nt/syntax-esc.html).

solstice333
  • 3,399
  • 1
  • 31
  • 28