错误:"|"此时是意外的批处理脚本 [英] Error: "|" was unexpected at this time batch script

查看:91
本文介绍了错误:"|"此时是意外的批处理脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行此脚本时,我收到

|这是出乎意料的.

| was unexpected at this time.

这是代码:

@ECHO Off

REM Mapeo de unidad U, path de usuario

    net use u: \\server\usuarios\%username%
pause
REM  ***** Description group ****

for /f %%i in ('net user %username% /domain | find /i /c Group') do set RESULT=%%i

echo %RESULT%

pause   

for句子中,i使用"',但是仍然出现错误.

In for sentence, i use " and ', but I still got error.

推荐答案

批处理解析器必须先解析for内部的条件,然后才能将其作为可执行命令传递给IN()子句,并且因为管道是DOS中的特殊字符,您需要在管道之前使用转义字符(^)来在初始批处理分析期间保留它,如下所示:

The condition inside the for must be parsed by the batch parser before it can pass it to the IN() clause as an executable command and since the pipe is a special character in DOS, you need to use escape character(^) before pipe to preserve it during the initial batch parsing, as shown below:

for /f %%i in ('net user %username% /domain ^| find /i /c Group') do set RESULT=%%i

这篇关于错误:"|"此时是意外的批处理脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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