0

I'm trying to set a varaible to the output of a command using a for loop, as another question on here discussed, but I'm getting stuck on some special characters that are screwing with the result. Here's what I've written:

for /f "delims=" %%i in ('netstat -b ^| find ""coresrvr.exe"" ^| find /c /v """"') do set output=%%i

That doesn't seem to be working though. It gives me "File not found - CORESRVR.EXE and then has the output = 0. What did I do wrong here?

Whitewind617
  • 357
  • 1
  • 2
  • 10
  • `set output = %%i` will set a variable named `output` to the value `%%i`; write `set "output=%%i"` (no spaces!) instead... – aschipfl Mar 16 '16 at 21:07

1 Answers1

0

Never mind I got it, the quote escaping was unnecessary. Here's the correct code:

for /f "delims=" %%i in ('netstat -b ^| find "coresrvr.exe" ^| find /c /v ""') do set output=%%i
Whitewind617
  • 357
  • 1
  • 2
  • 10
  • 1
    NO. You defined a variable named `'output '` with a space at the end, which I am pretty sure is not what you want. See [Declaring and using a variable in DOS/Windows batch file (.BAT)](http://stackoverflow.com/q/10552812/1012053) for more info. – dbenham Mar 17 '16 at 03:17
  • Oh shoot, I copied it over wrong, sorry. See I wrote all this remotely just for convenience sake, and I couldn't copy and paste it, so I just wrote it from scratch. It's correct in the actual code. Thanks though! – Whitewind617 Mar 18 '16 at 17:04