In a Windows batch file, can you chain something that is * not * another batch file?

I understand that if you have two files .bator .cmd, call them fooand barapply the following rules:

Without call:

:: Welcome to foo.bat
@bar.bat
@echo We never get to this line because bar.bat is "chain-executed".

C call:

:: Welcome to foo.bat
@call bar.bat
@echo This line is executed after bar.bat returns.

My question is: is there a way to perform the reverse operation, that is, to ensure that the non-batch file executable is linked?

:: Welcome to foo.bat
@chain bar.exe
@echo Even though bar is now an .exe,  we never get to this line.
@echo At least, that would be the case if the "chain" command really existed.

In other words, is there a way to execute the function of a dummy command chainin this last example?

+4
source share
1 answer

start .

@echo off
echo Welcome to %~nx0
start "Title" bar.exe & exit /B
echo Even though bar is now an .exe, we never get to this line.

bar.exe Title , .

start exit /B , bar.exe , .

, , , , cmd.exe /K, , .

, , , bar.exe .

@echo off
echo Welcome to %~nx0
start "Title" bar.exe & exit
echo Even though bar is now an .exe, we never get to this line.

exit /B, start bar.exe , cmd.exe /K.

start exit & , . p >

:

@echo off
echo Welcome to %~nx0
(
    start "Title" bar.exe
    exit /B
)
echo Even though bar is now an .exe, we never get to this line.

:

@echo off
echo Welcome to %~nx0
(
    start "Title" bar.exe
    exit
)
echo Even though bar is now an .exe, we never get to this line.

, , bar.exe .

1:
goto :EOF exit /B .

2: goto :EOF exit /B , , , call :label, , .

, call exit /B:

Test1.bat

@echo off
echo Running %~nx0
call Test2.bat
echo Finished %~nx0

Test2.bat

@echo off
echo Running %~nx0
Test3.bat
echo Finished %~nx0

Test3.bat

@echo off
echo Finished %~nx0

Test1.bat :

Running Test1.bat
Running Test2.bat
Finished Test3.bat
Finished Test1.bat

, Finished Test2.bat , Test3.bat Test1.bat.

C Test.exe:

#include <stdio.h>

int main (int argc, char* argv[])
{
    if(argc > 1)
    {
        printf("Running %s with argument %s\n",argv[0],argv[1]);
    }
    else
    {
        printf("Running %s without an argument\n",argv[0]);
    }
    return 0;
}

Test.exe :

Test4.bat

@echo off
echo Running %~nx0
Test.exe 4
call Test5.bat
echo Finished %~nx0

Test5.bat

@echo off
echo Running %~nx0
Test.exe 5
Test.exe 6 & exit /B
echo Finished %~nx0

Test4.bat :

Running Test4.bat
Running Test.exe with argument 4
Running Test5.bat
Running Test.exe with argument 5
Running Test.exe with argument 6
Finished Test4.bat

, Finished Test5.bat , Test.exe 6 Test4.bat.

bar & exit /B , bar - bat cmd exe com. , Test2.bat :

@echo off
echo Running %~nx0
Test3.bat & exit /B
echo Finished %~nx0

Test1.bat :

Running Test1.bat
Running Test2.bat
Finished Test3.bat

, exit /B, , exit .

+3

Source: https://habr.com/ru/post/1619542/


All Articles