如何从批处理文件中执行ping服务器只有一次? [英] How to ping a server only once from within a batch file?

查看:427
本文介绍了如何从批处理文件中执行ping服务器只有一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习如何编写批处理脚本,并试图创建一个自动运行一次在命令行命令的脚本:

I want to learn how to write batch scripts and tried to create a script which automatically runs this command in the command line once:

ping www.google.de -t

和显示平,所以它看起来是这样的:

and displays the ping, so it would look like this:

Reply from XXX.XXX.X.XX: time=30ms
Reply from XXX.XXX.X.XX: time=31ms
Reply from XXX.XXX.X.XX: time=29ms

我的问题是,这将导致此当我执行这个命令脚本:

My problem is, that this will result in this when I execute this command as script:

我的问题是,它不会在屏幕截图中显示控制台窗口作为其执行ping命令所有,但只需插入命令无限次。

My problem is that it will not execute the ping command at all, but just insert the command unlimited times in the console window as its shown in the screenshot.

我刚刚创建一个新的文件,写了平www.google.de -t 在里面,它保存为 ping.bat 文件并双击执行时就可以了。

I just created a new file, wrote ping www.google.de -t in it, saved it as ping.bat file and executed it with double clicking on it.

那么如何编写批处理文件来一次启动该命令并显示结果平?

So how to write the batch file to start this command only once and display the ping result?

推荐答案

在命令提示符窗口平/?输入和读取之后pressing短期帮助输出返回。或采取一看

Enter in a command prompt window ping /? and read the short help output after pressing RETURN. Or take a look on


  • - Windows XP文档

  • - Microsoft TechNet文章

  • Ping - Windows XP documentation
  • Ping - Microsoft TechNet article

解释微软定选项 -t

将ping指定的主机,直到停止。要查看统计信息并继续键入Control-中断。要停止键入Control-C。

Pings the specified host until stopped. To see statistics and continue type Control-Break. To stop type Control-C.

您可能需要使用:

@%SystemRoot%\system32\ping.exe -n 1 www.google.de

还是要首先检查服务器是否可用:

Or to check first if a server is available:

@echo off
set MyServer=Server.MyDomain.de
%SystemRoot%\system32\ping.exe -n 1 %MyServer% >nul
if errorlevel 1 goto NoServer

echo %MyServer% is availabe.
rem Insert commands here, for example 1 or more net use to connect network drives.
goto :EOF

:NoServer
echo %MyServer% is not availabe yet.
pause
goto :EOF

这篇关于如何从批处理文件中执行ping服务器只有一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆