将带有空格的参数传递给批处理文件

发布于 2024-10-05 19:41:58 字数 324 浏览 0 评论 0原文

我确信答案就像将“”传递给批处理文件中的参数一样简单。但这失败了。这就是我正在尝试做的事情。

Test.bat env "Some cmd"

这个“Some cmd”是另一个需要在env设置的环境中运行的命令。

Test.bat:

Something like  set Env with %1%

set cmd=%2%

%cmd%

以上失败,并显示“某些 cmd”未被识别为 cmd。

我可以让它工作的唯一方法是在批处理文件中使用“%cmd%”。这是对的吗?

I am so sure answer is as simple as passing "" to the arguments in batch file. But this fails. Here is what I am trying to do.

Test.bat env "Some cmd"

This "Some cmd" is another command that needs to run in environment set by env.

Test.bat:

Something like  set Env with %1%

set cmd=%2%

%cmd%

The above fails with '"Some cmd"' is not recognized as a cmd.

Only way I can get this to work is if I use "%cmd%" in batch file. Is this right?

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

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

发布评论

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

评论(1

究竟谁懂我的在乎 2024-10-12 19:41:58

我认为您需要指定“Some cmd”所在的路径。

I think you need to specify path where "Some cmd" is present.

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