Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理文件:如果命令不起作用_Batch File - Fatal编程技术网

Batch file 批处理文件:如果命令不起作用

Batch file 批处理文件:如果命令不起作用,batch-file,Batch File,我有一个名为tst.bat的批处理文件: @echo off :_main set str=%1 call :_checkInput call :_strLen %str% echo %_strLen% exit /b :_checkInput if "%str:~0,1%" == """ set str=%str:~1% if "%str:~-1%" == """ set str=%str:~0,-1% goto :eof

我有一个名为tst.bat的批处理文件:

    @echo off

:_main
   set str=%1

   call :_checkInput
   call :_strLen %str%

   echo %_strLen% 

exit /b

:_checkInput

if "%str:~0,1%" == """ set str=%str:~1%       
if "%str:~-1%" == """ set str=%str:~0,-1%   

goto :eof

:_strLen
   setlocal enabledelayedexpansion
   set str=%1

   :_loop
      if /i "!str:~%len%,1!" neq "" set /a len+= 1 & goto :_loop
   (endlocal & set _strLen=%len%)
goto :eof
但由于某种原因,当我在命令提示符下键入
tst“Hello”
时,我收到一个错误,它说:“此时set是意外的。”。错误if来自_checkInput部分中的“if”命令


我将非常感谢你的帮助。谢谢。

正如您所怀疑的,这个问题与“

您可以使用
%~1
%1
中删除封闭空间


您可以使用
set“var=%var:=%“

感谢您编辑Magoo为什么不使用命令修饰符来删除周围的引号<代码>设置str=%~1@Squashman在Magoo的评论之前我不知道这是可能的。:)你有没有考虑打开一个CMD提示符并从调用命令中读取帮助?在cmd提示符下键入
call/?
。代码中的问题是语法无效:当第一个表达式扩展为
,因此比较运算符
==
实际被引用,这是不需要的;当第一个表达式扩展到另一个表达式时,您的
if
命令行变成类似于
if“?==”set…
,例如
,因此最后一个引号和所有(!)after被视为第二个比较表达式,这也是无效的;对于这种
if
比较,您需要使用。Add yeah您是对的Magoo。此行设置“var=%var:=%”完全替换了我的检查输入。非常感谢。我感谢你的帮助。干杯