如何在命令行中将文件内容作为参数传递?

编程入门 行业动态 更新时间:2024-10-28 03:28:37
本文介绍了如何在命令行中将文件内容作为参数传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我想跑步

>foo bar

但是bar随我在文件系统中的位置而变化.我想做的就是不必记住bar的正确值,就是将文件fizz保留在各自的文件夹中,以便我可以执行类似call

but bar changes depdending on where I am in my filesystem. What I'd like to do, so I don't have to remember the proper value of bar, is to keep a file fizz in the respective folders so I can do something like call

>foo fizz

这当然是开箱即用的.

which of course doesn't work out of the box. Neither does

>foo < fizz

因为foo不希望输入,只是一个参数.我找到了 Linux解决方案,但没有找到Windows.

because foo doesn't expect input, just a parameter. I found a solution for Linux, but nothing for Windows.

推荐答案

假设fizz包含单行且无空格,即单线

Assuming fizz contains a single line with no whitespace, the one-liner

for /F %i in (fizz) do @foo %i

将做您想要的.如果您要放入fizz的参数可能包含空格,请使用

will do what you want. If the argument you're putting into fizz may contain whitespace, use

for /F "delims=" %i in (fizz) do @foo "%i"

一次传递参数.如果将%字符放入批处理文件中,则将其加倍.

to pass the argument in one piece. Double the % characters if putting this into a batch file.

更多推荐

如何在命令行中将文件内容作为参数传递?

本文发布于:2023-07-08 05:22:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1072502.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   命令行   参数   文件   内容

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!