开发者

Windows Batch Script Feeding Arguments

开发者 https://www.devze.com 2023-01-25 00:15 出处:网络
Suppose you have a script that takes a couple of command-line arguments and dumps its results to stdout.

Suppose you have a script that takes a couple of command-line arguments and dumps its results to stdout.

Manually invoking this script will look like this:

perl foo.pl arg1 arg2 arg3

Without changing the script in question, is it possible under Windows to take the contents of a file (e.g., input.txt is a multi-line text file with arg{1,3} delimited by a whitespace on each line) and execute something like this:

foreach line in input.txt
  perl foo.pl current_line >> output.txt

Right now, I just have anothe开发者_Python百科r Perl script that does this, but was wondering if this was possible anyway.


I'm gonna say yes.

I searched the web with Google for windows batch loops and got this page: http://www.robvanderwoude.com/for.php.

I dug around on the site and found this page: http://www.robvanderwoude.com/ntfor.php#FOR_F

So it looks like the code would be something like...

FOR /F %%variable IN (input.txt) DO perl foo.pl %%variable >> output.txt
0

精彩评论

暂无评论...
验证码 换一张
取 消