2016-01-06 64 views
0

假设我有这样的批处理脚本:读取线之后每隔一行读

node1.log  
node2.log 
node3.log 
node4.log etc... 

我想逐行读取每一行并执行一个文本文件,执行命令

alan.exe node1.log node2.log 
alan.exe node3.log node4.log 

等..

完成此操作的最佳方法是什么?

+0

请注意,'DOS'是从上世纪80年代年/ 90操作系统!请改用标签Windows。代码正常。 – SteveFest

回答

0

试试这个。 File.txt将会有你的日志文件名。

@echo off 
setlocal enabledelayedexpansion 

FOR /F "delims=" %%G IN ('find /c /v "" ^<file.txt') DO SET NUM=%%G 

SET /A NUM=NUM/2 

< file.txt (
    FOR /L %%G IN (1,1,%NUM%) DO (
     SET /P LINE1= 
     SET /P LINE2= 
     echo mypgm.exe !LINE1! !LINE2! 
    ) 
) 
pause 

输出

mypgm.exe node1.log node2.log 
mypgm.exe node3.log node4.log 
mypgm.exe node5.log node6.log 
Press any key to continue . . . 

删除单词回声和你想运行的程序替换mypgm.exe。回声只是在那里为了概念的证明。

+0

嗨,squashman代码工作。谢谢您的帮助 – apurva

0

像这样:

@echo off 

setlocal enabledelayedexpansion 
set args= 
set n=2 
for /f "tokens=*" %%x in (file.txt) do (
    set args=!args! %%x 
    set /a n -= 1 
    if !n! EQU 0 (
     alan !args! 
     set args= 
     set n=2 
    ) 
) 
1
@echo off 
setlocal EnableDelayedExpansion 

for /F "delims=" %%a in (file.txt) do (
    if not defined line (
     set "line=%%a" 
    ) else (
     ECHO alan.exe !line! %%a 
     set "line=" 
    ) 
) 
相关问题