如何通过新线作为参数传递给一个bat文件的文本? [英] How to pass text with new line as parameter to a bat file?

查看:158
本文介绍了如何通过新线作为参数传递给一个bat文件的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我通过文字是这样的:

If I pass text like this:

first line
second line

要.bat文件,它走的是第一线只能作为一个参数值。

to a .bat file, it is taking the first line only as a parameter value.

我该如何解决这个问题?
谢谢

How can I fix this? Thanks

推荐答案

这几乎是不可能的批处理文件的参数内通过一个换行符。这是可以做到的,但我不认为任何人开发了一种务实的方法来正确读取一个批处理文件中这样的参数。

It is nearly impossible to pass a newline within a batch file argument. It can be done, but I don't think anyone has developed a pragmatic way to properly read such a parameter within a batch file.

您最好的办法是定义一个包含文本的两行,包括换行符的环境变量。然后通过该变量的名称作为参数传递给批处理,然后用扩张延迟让批处理文件访问的值。

Your best bet is to define an environment variable that contains the two lines of text, including the newline. Then pass the name of the variable as an argument to the batch and then let the batch file access the value using delayed expansion.

test.bat的:

test.bat:

@echo off
setlocal enableDelayedExpansion
echo !%1!

在命令行中:

>set multiLine=hello^
More?
More? world

>test multiLine
hello
world

有关任何有兴趣,这里是关于批处理参数换行符杰布发起讨论:的 http://www.dostips.com/forum/viewtopic.php?t=1768

For anyone interested, here is a discussion initiated by jeb concerning newlines in batch parameters: http://www.dostips.com/forum/viewtopic.php?t=1768

这篇关于如何通过新线作为参数传递给一个bat文件的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆