0

I am running the following command within a batch script:

netsh advfirewall firewall show rule name ="MyCustomRule"

And it gives out either a string "No rules match the specified criteria." or multiple rows.

I would like to be able to assign its output to a variable something like:

set a = output(netsh advfirewall firewall show rule name ="MyCustomRule")

Such that I can further do if "%a%" == "" . Is it possible?

SummerCode
  • 1,403
  • 1
  • 14
  • 28
  • Possible duplicate of [Assign output of a program to a variable](https://stackoverflow.com/questions/2323292/assign-output-of-a-program-to-a-variable) – phuclv Mar 10 '18 at 08:59

2 Answers2

1

It's possible, although I doubt that it will be fun dealing with all the blanks in your string.

Another approach would be using the commands FIND or FINDST to check your output for the presence of a substring and then to do IF statements based on the %ERRORLEVEL% generated by these commands.

Florian Straub
  • 826
  • 9
  • 18
1

Did you mean something like that :

@echo off
for /f "delims=" %%a in ('netsh advfirewall firewall show rule name^="MyCustomRule"') do (
    Set "Output=%%a"
)
Echo Output Result = "%OutPut%"
pause
Hackoo
  • 18,337
  • 3
  • 40
  • 70