Batch File: Hide Ping test results

26,710

redirect the output to nul:

ping -n 1 %computer_name%  | find "Reply" > nul

this will still correctly set the %errorlevel% if the string was or was not found, but also hide the output.

Share:
26,710

Related videos on Youtube

thegreyspot
Author by

thegreyspot

Updated on September 17, 2022

Comments

  • thegreyspot
    thegreyspot over 1 year

    I'm making a batch file that tests a Computer name and sees if it responds.

    However when I run it, even with the "@echo off", I still see the reply being sent and so on. How can I hide that?

  • Joey
    Joey over 14 years
    And, in most cases, just to be sure, stick a 2>&1 at the end as well. Many programs (ping and find apparently not) emit error messages to stderr.
  • Teddy
    Teddy over 14 years
    @Johannes Rössel: No. This is DOS, not Unix.
  • Teddy
    Teddy over 14 years
    Surely it's "nul:", not "nul"?
  • John T
    John T over 14 years
    I think people use nul: because files cannot be created with a colon in their name on Windows, so it will revert to nul by itself. Even an example from Microsoft on how to invoke DOS commands uses nul by itself: support.microsoft.com/kb/40592