因此,假设你有一个文件 bar.bat,它说 echo This is bar.bat!,你想从一个文件 foo.bat调用它,你可以在 foo.bat中写下这些:
if "%1"=="blah" bar
从命令行运行 foo blah,您将看到:
C:\>foo blah
C:\>if "blah" == "blah" bar
C:\>echo This is bar.bat!
This is bar.bat!
But beware: When you invoke a batch script from another batch script, the original batch script will stop running. If you want to run the secondary batch script and then return to the previous batch script, you'll have to use the call command. For example:
if "%1"=="blah" call bar
echo That's all for foo.bat!
如果你在上面运行 foo blah,你会看到:
C:\>foo blah
C:\>if "blah" == "blah" call bar
C:\>echo This is bar.bat!
This is bar.bat!
C:\>echo That's all for foo.bat!
That's all for foo.bat!