Batch File: Error in relative path , one level up from the current directory

馋奶兔 提交于 2019-12-12 11:28:07

问题


I am new to the batch script programming.Getting error while executing batch file if I give the relative path. I have following folder structure

Script folder - C:\batch\script\ServiceRegister.bat
Bin path - C:\batch\bin\ERecruitGenerateReportsWindowsService.exe

ServiceRegister.bat Batch file –

%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe %~dp0%~1\bin\ERecruitGenerateReportsWindowsService.exe

When I execute ServiceRegister.bat file I got the error:

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.

I am using “%~dp0%~1” to go one level up in the directory still it gets its current path.

%~dp0%~1 - C:\batch\script\  

I need the C:\batch\ path. How I can get this path? It works fine If I give the absolute path -

%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\batch\bin\ERecruitGenerateReportsWindowsService.exe

回答1:


Your attempt to use %~1 to go up one level in the directory structure is inventive and totally invalid syntax. The proper syntax is just as simple - use ..\.

A leading \ is not required because %~dp0 ends with a \.

%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe %~dp0..\bin\ERecruitGenerateReportsWindowsService.exe


来源:https://stackoverflow.com/questions/16960880/batch-file-error-in-relative-path-one-level-up-from-the-current-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!