Windows 批处理脚本输入参数

发布于 2024-10-02 18:12:53 字数 386 浏览 0 评论 0原文

假设您有一个脚本,它接受几个命令行参数并将其结果转储到 stdout

手动调用此脚本将如下所示:

perl foo.pl arg1 arg2 arg3

在不更改相关脚本的情况下,Windows 下是否可以获取文件的内容(例如,input.txt 是一个带有 < code>arg{1,3} 每行由空格分隔)并执行如下操作:

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

现在,我只有另一个 Perl 脚本可以执行此操作,但想知道这是否可能。

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 another Perl script that does this, but was wondering if this was possible anyway.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

垂暮老矣 2024-10-09 18:12:53

我会说是的。

我在 Google 上搜索了 windows 批处理循环 并得到了此页面:http:// /www.robvanderwoude.com/for.php

我在网站上查找并找到了此页面:http://www.robvanderwoude.com/ntfor。 php#FOR_F

所以看起来代码会是这样的......

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文