在批处理文件中包含批处理文件

Dim*_*ris 5 c# batch-file

在尝试使用时运行所有内容时,从另一个批处理文件调用批处理文件时出现问题Process.Start.基本上我调用从我的c#程序执行批处理文件,如下所示:


call include.bat  

//execute the rest of the batch file here  

Run Code Online (Sandbox Code Playgroud)

include.bat文件设置路径,可以由许多其他批处理文件使用.当我运行时,Process.Start有时这是有效的,有时我得到ERROR: cannot find include.bat.首先,任何想法为什么会发生这种情况?关于如何从批处理文件中解决这个问题的想法?

Bot*_*000 6

要切换到批处理文件所在的目录,请使用以下命令:

cd %~dp0
Run Code Online (Sandbox Code Playgroud)

我几乎在所有批处理脚本中都这样做.这样,相对路径应始终有效.

  • 我通常设置一个 var 以便脚本更易于阅读: SET CDIR=%~dp0 (2认同)