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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.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 该命令的语法不正确:for loop batch_Batch File - Fatal编程技术网

Batch file 该命令的语法不正确:for loop batch

Batch file 该命令的语法不正确:for loop batch,batch-file,Batch File,我正在制作一个批处理脚本来停止几个服务,但是我在serviceList.TEMP中的哪个循环的第二秒得到语法不正确的错误 echo to serviceList.TEMP中的>是否应该是>>以便附加到文件中 echo !num!>>serviceList.TEMP 在这种情况下,还应确保在追加操作之前删除该文件 另外,我假设您在尝试读取serviceList.TEMP文件的行时错过了FOR循环中的/F,是吗 FOR %%X in (serviceList.TEMP) do ( 应

我正在制作一个批处理脚本来停止几个服务,但是我在serviceList.TEMP中的哪个循环的第二秒得到语法不正确的错误


echo to serviceList.TEMP中的>是否应该是>>以便附加到文件中

echo !num!>>serviceList.TEMP
在这种情况下,还应确保在追加操作之前删除该文件

另外,我假设您在尝试读取serviceList.TEMP文件的行时错过了FOR循环中的/F,是吗

FOR %%X in (serviceList.TEMP) do (
应该是

FOR /F %%X in (serviceList.TEMP) do (
?

另外,您可以通过执行以下操作将std out和err附加到同一个文件中

someprocesshere 1> out.log 2>&1

echo to serviceList.TEMP中的>是否应该是>>以便附加到文件中

echo !num!>>serviceList.TEMP
在这种情况下,还应确保在追加操作之前删除该文件

另外,我假设您在尝试读取serviceList.TEMP文件的行时错过了FOR循环中的/F,是吗

FOR %%X in (serviceList.TEMP) do (
应该是

FOR /F %%X in (serviceList.TEMP) do (
?

另外,您可以通过执行以下操作将std out和err附加到同一个文件中

someprocesshere 1> out.log 2>&1
问题在于:

 FOR %%X in (serviceList.TEMP) do ( 

     set /a "SKIP_LINES=%%G+7"

     set secondForFilter="skip=%SKIP_LINES%"


 FOR /F %secondForFilter% %%Z in (services.TEMP) do (   
    call debug.cmd  REM  debug.cmd -> echo debug pause>nul
当您在括号中设置值时,通常的方法是使用,但对于参数化的选项,它不起作用

这里需要一个子程序

你已经进入了for循环。GOTO中断上下文,执行GOTO后将不调用循环

和rem不能在没有&

尽管我无法检查bat的逻辑,但请考虑以下内容:

setlocal EnableDelayedExpansion
setlocal enableExtensions


::queryex output file
sc queryex>services.TEMP                    
find /i /N "DISPLAY_NAME: Hotspot" services.TEMP>tmp1.TEMP


FOR /F "skip=2" %%G in (tmp1.TEMP) do (

 set num=%%G
 set num=!num:~1,3!
 echo !num!>serviceList.TEMP

)



 FOR %%X in (serviceList.TEMP) do ( 

    call :subroutine %%G

)

del /S *.TEMP >>debug.txt 2>>debug.txt
exit /b %errorlevel%

:subroutine
setlocal enableDelayedExpansion

set /a skiplines=%~1+7
set "filter="skip=%skiplines%""

     FOR /F %filter% %%Z in (services.TEMP) do (   
        call debug.cmd  

        set serv=%%Z
        rem extract PID
        set "serv=!serv: =!"
        set "serv=!serv::=!"                        
        set procID=!serv!                   


         taskkill  /pid !procID! /f >>debug.txt 2>>debug.txt
         goto :break_for

     ) 
    :break_for
endlocal
exit /b
问题在于:

 FOR %%X in (serviceList.TEMP) do ( 

     set /a "SKIP_LINES=%%G+7"

     set secondForFilter="skip=%SKIP_LINES%"


 FOR /F %secondForFilter% %%Z in (services.TEMP) do (   
    call debug.cmd  REM  debug.cmd -> echo debug pause>nul
当您在括号中设置值时,通常的方法是使用,但对于参数化的选项,它不起作用

这里需要一个子程序

你已经进入了for循环。GOTO中断上下文,执行GOTO后将不调用循环

和rem不能在没有&

尽管我无法检查bat的逻辑,但请考虑以下内容:

setlocal EnableDelayedExpansion
setlocal enableExtensions


::queryex output file
sc queryex>services.TEMP                    
find /i /N "DISPLAY_NAME: Hotspot" services.TEMP>tmp1.TEMP


FOR /F "skip=2" %%G in (tmp1.TEMP) do (

 set num=%%G
 set num=!num:~1,3!
 echo !num!>serviceList.TEMP

)



 FOR %%X in (serviceList.TEMP) do ( 

    call :subroutine %%G

)

del /S *.TEMP >>debug.txt 2>>debug.txt
exit /b %errorlevel%

:subroutine
setlocal enableDelayedExpansion

set /a skiplines=%~1+7
set "filter="skip=%skiplines%""

     FOR /F %filter% %%Z in (services.TEMP) do (   
        call debug.cmd  

        set serv=%%Z
        rem extract PID
        set "serv=!serv: =!"
        set "serv=!serv::=!"                        
        set procID=!serv!                   


         taskkill  /pid !procID! /f >>debug.txt 2>>debug.txt
         goto :break_for

     ) 
    :break_for
endlocal
exit /b

我想它在services.TEMP do?1中的/F%secondForFilter%%%Z这行崩溃了。了解。2.检查%%G循环的右括号。我想它在services.TEMP do?1中的/F%secondForFilter%%%Z这一行崩溃了。了解。2.检查%%G循环的右括号。