【问题标题】:How can I preserve spaces in user input for bat scripts?如何在用户输入中为 bat 脚本保留空格?
【发布时间】:2012-05-18 18:27:55
【问题描述】:

我有一个 bat 脚本可以从 Active Directory 中转储用户名列表及其显示名称。在我们需要从有空格的组中转储名称之前,它非常有效。

@echo off
Set /p GROUP="Group Name: "

echo This window will close when finished!
echo Larger groups may take awhile!

 dsquery group -name %Group% | DSGET group -members | dsget user -samid -display > %GROUP%.txt

有没有办法通过用户输入来保留空格?这是一个正在工作的远程服务器,所以我没有安装应用程序或任何东西的权限,只是创建基本脚本。

【问题讨论】:

    标签: batch-file spaces preserve


    【解决方案1】:

    是的,只需将 var 字符串包含在 "" 中,试试这个:

    dsquery 组 -name "%Group%" | DSGET 组成员 | dsget user -samid -display > %GROUP%.txt

    【讨论】:

    • 哇.. 在所有要尝试的事情中,这很简单,而且看起来很简单.. 哈哈。谢谢,我刚刚应用它,脚本运行完美!
    猜你喜欢
    • 2016-03-20
    • 1970-01-01
    • 1970-01-01
    • 2015-05-07
    • 2023-02-09
    • 2019-01-03
    • 2012-03-24
    • 1970-01-01
    • 2015-07-04
    相关资源
    最近更新 更多