我如何得到一个批处理文件从一个txt文件接受输入? [英] how do i get a batch file to accept input from a txt file?

查看:127
本文介绍了我如何得到一个批处理文件从一个txt文件接受输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在多台计算机上的批处理文件运行命令。

I would like to run commands in a batch file on multiple computers.

例如:

@echo off
ping %1
pause
exit

如果这个批处理文件被称为pingme.bat和I型 pingme.bat yahoo.com 那就ping通yahoo.com。我的问题是我想要的批处理文件,以从文本文件接受输入。

If this batch file were called pingme.bat and I type pingme.bat yahoo.com then it would ping yahoo.com. My problem is I want the batch file to accept input from a text file.

像这样 pingme.bat computers.txt ,它会读取文件中列出的计算机的名称,做我指定要做给他们任何命令。

Like so pingme.bat computers.txt and it would read the names of computers listed in the file and do whatever command I specify to be done to them.

%1 接受当我输入的批处理文件,我指定的投入,现在我想批处理文件来读取TXT线并做到这一点。

%1 accepts the input I specify when I type the batch file, now I would like to the batch file to read the lines in the txt and do it.

在文本中的行以列表的形式不使用逗号或任何东西。

The lines in the text are in list form not using commas or anything.

推荐答案

这样做的一个方法是放置网址,像这样的文本文件:

One way to do so would be to place the URLS in a text file like so:

www.google.com搜索
www.yahoo.com

www.google.com
www.yahoo.com

然后运行以下批处理

for /f %%a in (%1) do (
echo Pinging %%a...
ping %%a
)

和从CMD运行它pingme.bat URLs.txt

and run it from cmd as pingme.bat URLs.txt

另外,您也可以在该批次中指定文本文件的名称,没有参数运行

Alternatively, you may specify the text file's name within the batch, and run it without the parameter

for /f %%a in (URLs.txt) do (
echo Pinging %%a...
ping %%a
)

这里是另一种方法

此特定批次将拉动从列表中,并写入到output.txt如果ping成功

This particular batch will pull from the list, and write to output.txt if the ping was successful

@ECHO OFF
SET output=output.txt
IF EXIST "%output%" DEL "%output%"
FOR /f %%a IN (URLs.txt) DO (
    CALL :ping %%a

)
GOTO :EOF

:ping
ping -n 1 %1 | find "Approximate round trip" >NUL || ECHO %1>>"%output%"

希望这台你在正确的方向。

Hopefully that sets you in the right direction.

这篇关于我如何得到一个批处理文件从一个txt文件接受输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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