Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 如何:批量读取列表,将内容输出到日志文件_List_Batch File_For Loop_Goto - Fatal编程技术网

List 如何:批量读取列表,将内容输出到日志文件

List 如何:批量读取列表,将内容输出到日志文件,list,batch-file,for-loop,goto,List,Batch File,For Loop,Goto,我记不起如何读取文本文件的行并执行某种任务。例如,我试图读取文本文件(一组主机名)的内容,然后在这些主机上执行任务列表,以查看进程是否正在运行 @echo off set MachineList=computers.log FOR /f "delims= " %%a in (%MachineList%) DO GOTO :GETINFO :GETINFO echo %%a >>results.log tasklist /s \\%%a | findstr /i iexplore

我记不起如何读取文本文件的行并执行某种任务。例如,我试图读取文本文件(一组主机名)的内容,然后在这些主机上执行任务列表,以查看进程是否正在运行

@echo off

set MachineList=computers.log

FOR /f "delims= " %%a in (%MachineList%) DO GOTO :GETINFO

:GETINFO
echo %%a >>results.log
tasklist /s \\%%a | findstr /i iexplore.exe >>results.log

这似乎不起作用,我也不知道我做错了什么。日志实体仅显示输出的“%a”。几年前我一直在做这类事情。我想“不要用它,你会失去它”是一天的顺序。似乎a应该在某处设置另一个变量,但我不记得在哪里。

您有几个小错误。“delims=”选项必须没有结束空格。%%a可替换参数必须在FOR命令的同一行中使用;如果在不同的行中使用,则必须用以FOR命令开头的括号分隔,但在您的情况下,这不是必需的,因为您只想在FOR中执行一个命令。任务列表命令应与文本文件的每一行一起执行。最后,FINDSTR命令查看iexplore.exe的这些结果

@echo off
set MachineList=computers.log
FOR /f "delims=" %%a in (%MachineList%) DO tasklist /s \\%%a >>results.log
findstr /i iexplore.exe results.log

我想你可以试试这个:

@echo off

set MachineList=computers.log

FOR /f "delims= " %%a in (%MachineList%) DO CALL :GETINFO

:GETINFO
echo %%a >>results.log
tasklist /s \\%%a | findstr /i iexplore.exe >>results.log