【发布时间】:2013-06-06 11:23:37
【问题描述】:
我是批处理脚本编程的新手。如果我提供相对路径,则在执行批处理文件时会出错。 我有以下文件夹结构
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
【问题讨论】:
标签: windows batch-file path