我是批处理脚本编程的新手。如果我给出相对路径,则在执行批处理文件时会出错。我有以下文件夹结构
Script folder - C:\batch\script\ServiceRegister.bat
Bin path - C:\batch\bin\ERecruitGenerateReportsWindowsService.exe
ServiceRegister.bat 批处理文件 –
%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe %~dp0%~1\bin\ERecruitGenerateReportsWindowsService.exe
当我执行 ServiceRegister.bat 文件时,出现错误:
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\batch\script\bin\ERecruitGenerateReportsWindowsService.exe' or one of its dependencies. The system cannot find the file specified.
我正在使用“%~dp0%~1”在目录中向上移动一级,但它仍然获得其当前路径。
%~dp0%~1 - C:\batch\script\
我需要 C:\batch\ 路径。我怎样才能得到这条路?如果我给出绝对路径,它工作正常 -
%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\batch\bin\ERecruitGenerateReportsWindowsService.exe