【问题标题】:Specify a relative path where an absolute is required in batch file指定批处理文件中需要绝对路径的相对路径
【发布时间】:2014-01-15 23:45:42
【问题描述】:

我有以下批处理文件:

"C:\TapTest\PsExec.exe" /accepteula -i -s "C:\TapTest\tapinstall.exe" 
    ->  install "C:\TapTest\driver\OemWin2k.inf" tap0901

批处理文件的位置是:

c:\TapTest\TapInstall.bat

我希望能够执行以下操作(使用相对路径):

"PsExec.exe" /accepteula -i -s "tapinstall.exe" install "driver\OemWin2k.inf" tap0901

但是 tapinstall.exe 需要一个绝对路径作为参数。如何在不硬编码的情况下让批处理文件给出绝对路径?

【问题讨论】:

    标签: windows batch-file relative-path absolute-path


    【解决方案1】:
    "PsExec.exe" /accepteula -i -s "%~dp0tapinstall.exe" install "%~dp0driver\OemWin2k.inf" tap0901
    

    %0 = 引用当前批处理文件

    %~dp0 = 批处理文件所在的驱动器和路径


    【讨论】:

    • 非常感谢。我编辑了您的答案,也将%~dp0 添加到tapinstall.exe。正在等待审核。
    • @MC ND:如何在 PowerShell 中实现它..??
    • @Koder101 $ScriptDirectory = Split-Path $script:MyInvocation.MyCommand.Path
    猜你喜欢
    • 2012-04-30
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    • 2018-03-26
    • 2011-06-30
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多