windows 创建一个在cmd上运行某个命令的bat文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23576425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a bat file that runs a certain command on cmd
提问by MichaelCX
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. 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. I tried just putting in ping 216.52.241.254 -t
and it just spams it over and over again.
所以通常我可以在cmd
窗口中输入ping 216.52.241.254 -t
它,它会告诉我我对某个服务器的 ping。如何创建一个.bat
自动打开cmd
窗口并输入的文件,这样我就不必每次都写出来。我试着把ping 216.52.241.254 -t
它放进去,它只是一遍又一遍地发送垃圾邮件。
回答by Monacraft
Another way of doing this (potentially a lot easier for you) would be to create a shortcut:
另一种方法(可能对你来说更容易)是创建一个快捷方式:
- Right Click in windows explorer and hover over "
New
" - Select "
Shortcut
" - A dialogue will pop-up. Enter the command you wish to utilize:
ping 216.52.241.254 -t
- Click Next and name the file.
- Now whenever you open the shortcut, it will execute the command.
- 在 Windows 资源管理器中右键单击并将鼠标悬停在“
New
”上 - 选择“
Shortcut
” - 将弹出一个对话框。输入您要使用的命令:
ping 216.52.241.254 -t
- 单击下一步并命名文件。
- 现在,无论何时打开快捷方式,它都会执行命令。
The advantage of this method over the other is its simpler and allows you to pin it to the Starmenu or Taskbar.
这种方法相对于另一种方法的优点是它更简单,并允许您将其固定到 Starmenu 或任务栏。
Mona.
莫娜。
回答by Monacraft
Very simple:
很简单:
@echo off
ping 216.52.241.254 -t
Echo.
pause
- Open Notepad
- Copy and paste this in.
- Save as a
.bat
file, ensuring that you select "all files
" option - Run the batch file any time you want to check your ping.
- 打开记事本
- 复制并粘贴这个。
- 另存为
.bat
文件,确保您选择“all files
”选项 - 在您想要检查 ping 的任何时候运行批处理文件。
Done!
完毕!
回答by foxidrive
It spammed it over and over because you called the batch file ping
so it was launching itself.
它一遍又一遍地发送垃圾邮件,因为您调用了批处理文件,ping
因此它会自行启动。
回答by ilias sld
type the following:
键入以下内容:
cd\
ping -t 216.52.241.254
回答by VipiN Negi
You must have keep the file name as 'ping.bat'. Rename it to something else and it will definitely work. ex : ping1.bat, something.bat etc., anything else but ping.
您必须将文件名保留为“ ping.bat”。将其重命名为其他名称,它肯定会起作用。例如:ping1.bat、something.bat 等,除了 ping 之外的其他任何东西。
回答by Acryte
It spams it again and again because you used -t which "Pings the specified host until stopped." if you lose the -t it won't do that. Type Ping /? to look through all the options available when using ping and select what is appropriate for what you want it to do.
它一次又一次地发送垃圾邮件,因为您使用了 -t,它“Ping 指定的主机直到停止”。如果你失去了 -t 它不会那样做。类型平/?查看使用 ping 时可用的所有选项并选择适合您希望它执行的操作的选项。