-2

I would like to make a ping script that instead of saying "request timed out" it returns something else such as "offline."

I want this to to be output while ping is running not after the command completes.

I am using batch files for cmd

I want this command so when I ping someone it looks more flavorful than request times out.

I am currently trying to find commands that allow me to substitute txt for other txt I have not been successful yet but I do think I am getting closer.

I am experimenting with | find “Request timed out” and if that does work I still don’t know the command that would allow me to replace that txt with what I want.

3
  • I have tried many things in batch none seem to work
    – Wings
    Oct 8, 2018 at 18:20
  • 1
    Why do you want to do that? If you ping a server that doesn't exist it is not offline ...
    – DavidPostill
    Oct 8, 2018 at 20:25
  • 1
    Please edit your question to tell us specifically what you've tried. Saying you tried many things does not help us know what you tried or where you're stuck. Oct 8, 2018 at 23:41

1 Answer 1

1

The output of ping can be piped to sed for Windows:

ping example.com | sed "s/Request timed out./Replacement Text/"

In the above example, the text Request timed out. is replaced with Replacement Text.

18
  • Not really a portable solution being sed doesn’t exist in Windows. Oct 8, 2018 at 20:05
  • @Appleoddity sed doesn't exist by default in Windows, but a compiled version exists for download in the link I provided. Oct 8, 2018 at 21:34
  • 1
    @Wings ping returns an errorlevel when it is successful or not. Simply redirect the output of ping to NUL (>NUL 2>&1) and echo whatever text you want based on a conditional if statement then loop and repeat. Nobody is in to writing code for others here. You have to show you at least researched and tried and where you’re confused to get help which is what others have asked you to do. Oct 9, 2018 at 1:57
  • 1
    @Wings Listen, you’re welcome to visit us at Superuser with your questions. But there are some basic ground rules to follow. Please read How to Ask and EDIT your original question and add all pertinent information you would like to provide, including code samples, error messages, examples of what you are looking for, etc. use proper code formatting so that your question is clear and easy to read. Comments are NOT for back and forth discussion. That is how you get a quality answer. What you are doing now is not. Oct 9, 2018 at 13:47
  • 1
    @Wings edit your question to show what you have tried. It would also be helpful to know what platform you are using and why you want this behavior. Oct 9, 2018 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .