Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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_Cmd_Batch Processing_Command Prompt - Fatal编程技术网

Batch file 如何检查批处理过程是否成功执行

Batch file 如何检查批处理过程是否成功执行,batch-file,cmd,batch-processing,command-prompt,Batch File,Cmd,Batch Processing,Command Prompt,我试图创建一个windows批处理脚本来安装nodeJs、express和bower,但目前无法运行,我也不知道问题出在哪里,因为终端在几秒钟后关闭了。 如果我将批处理脚本的所有指令逐一运行到CMD中,则所有工作正常。 如何验证每个流程都已成功执行?我的意思是,如果express的安装失败,则会收到一条消息,如“fail express framework install” 我认为问题在于脚本在尝试安装下一个代码块时没有等待完成安装第一个代码块。 有什么解决办法吗? 这是我的脚本: 这就是IF

我试图创建一个windows批处理脚本来安装nodeJs、express和bower,但目前无法运行,我也不知道问题出在哪里,因为终端在几秒钟后关闭了。 如果我将批处理脚本的所有指令逐一运行到CMD中,则所有工作正常。 如何验证每个流程都已成功执行?我的意思是,如果express的安装失败,则会收到一条消息,如
“fail express framework install”
我认为问题在于脚本在尝试安装下一个代码块时没有等待完成安装第一个代码块。 有什么解决办法吗?
这是我的脚本:



这就是
IF
语句中
ERRORLEVEL
关键字的用途。有关详细信息,请参见
IF/?

C:\...>if /?
Performs conditional processing in batch programs.

IF [NOT] ERRORLEVEL number command
....

  NOT               Specifies that Windows should carry out
                    the command only if the condition is false.

  ERRORLEVEL number Specifies a true condition if the last program run
                    returned an exit code equal to or greater than the number
                    specified.
....
%ERRORLEVEL% will expand into a string representation of
the current value of ERRORLEVEL, provided that there is not already
an environment variable with the name ERRORLEVEL, in which case you
will get its value instead.  After running a program, the following
illustrates ERRORLEVEL use:

    goto answer%ERRORLEVEL%
    :answer0
    echo Program had return code 0
    :answer1
    echo Program had return code 1

You can also use numerical comparisons above:

    IF %ERRORLEVEL% LEQ 1 goto okay
....
C:\...>

只要命令设置退出状态(许多命令都设置了退出状态),这就可以工作

运行程序并检查
errorlevel
variavle,如果它为`=0`则成功运行,否则为错误
C:\...>if /?
Performs conditional processing in batch programs.

IF [NOT] ERRORLEVEL number command
....

  NOT               Specifies that Windows should carry out
                    the command only if the condition is false.

  ERRORLEVEL number Specifies a true condition if the last program run
                    returned an exit code equal to or greater than the number
                    specified.
....
%ERRORLEVEL% will expand into a string representation of
the current value of ERRORLEVEL, provided that there is not already
an environment variable with the name ERRORLEVEL, in which case you
will get its value instead.  After running a program, the following
illustrates ERRORLEVEL use:

    goto answer%ERRORLEVEL%
    :answer0
    echo Program had return code 0
    :answer1
    echo Program had return code 1

You can also use numerical comparisons above:

    IF %ERRORLEVEL% LEQ 1 goto okay
....
C:\...>