简体   繁体   English

创建在cmd上运行某个命令的bat文件

[英]Creating a bat file that runs a certain command on cmd

So normally I can type this into the cmd window ping 216.52.241.254 -t and it tells me my ping to a certain server. 所以通常我可以在cmd窗口ping 216.52.241.254 -t键入它,它告诉我我对某个服务器的ping。 How can I create a .bat file that automatically opens the cmd window and types it in so that I don't have to write it out every single time. 如何创建一个自动打开cmd窗口并将其键入的.bat文件,这样我就不必每次都写出来。 I tried just putting in ping 216.52.241.254 -t and it just spams it over and over again. 我试着直接输入ping 216.52.241.254 -t ,它只是ping 216.52.241.254 -t它。

Another way of doing this (potentially a lot easier for you) would be to create a shortcut: 另一种方法(可能对您来说更容易)是创建一个快捷方式:

  1. Right Click in windows explorer and hover over " New " 在Windows资源管理器中右键单击并将鼠标悬停在“ New ”上
  2. Select " Shortcut " 选择“ Shortcut
  3. A dialogue will pop-up. 弹出对话框。 Enter the command you wish to utilize: ping 216.52.241.254 -t 输入您要使用的命令: ping 216.52.241.254 -t
  4. Click Next and name the file. 单击“下一步”并命名该文件。
  5. Now whenever you open the shortcut, it will execute the command. 现在每当您打开快捷方式时,它都会执行该命令。

The advantage of this method over the other is its simpler and allows you to pin it to the Starmenu or Taskbar. 这种方法优于另一种方法的优点是它更简单,并允许您将其固定到Starmenu或任务栏。

Mona. 莫娜。

它一遍又一遍地发送垃圾邮件,因为你调用了批处理文件ping所以它自己启动了。

Very simple: 很简单:

@echo off
ping 216.52.241.254 -t
Echo.
pause
  1. Open Notepad 打开记事本
  2. Copy and paste this in. 将其复制并粘贴到其中。
  3. Save as a .bat file, ensuring that you select " all files " option 保存为.bat文件,确保选择“ all files ”选项
  4. Run the batch file any time you want to check your ping. 每次要检查ping时都运行批处理文件。

Done! 完成!

type the following: 输入以下内容:

cd\ 
ping -t 216.52.241.254 

It spams it again and again because you used -t which "Pings the specified host until stopped." 它一次又一次地垃圾邮件,因为你使用了-t“指定主机直到停止”。 if you lose the -t it won't do that. 如果你失去-t就不会那样做。 Type Ping /? 输入Ping /? to look through all the options available when using ping and select what is appropriate for what you want it to do. 查看使用ping时可用的所有选项,并选择适合您希望它执行的操作。

You must have keep the file name as ' ping.bat '. 您必须将文件名保留为“ ping.bat ”。 Rename it to something else and it will definitely work. 将它重命名为其他东西,它肯定会起作用。 ex : ping1.bat, something.bat etc., anything else but ping. 例如:ping1.bat,something.bat等,除了ping之外的其他任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM