【问题标题】:Run batch file which run another cmd file运行运行另一个 cmd 文件的批处理文件
【发布时间】:2014-10-15 00:07:28
【问题描述】:

我在批处理文件中有脚本:

cd C:\TESTS\front-tests
call git pull
cd C:\TEST\front-tests\AutoApp\bin\debug
start AutoApp.exe

我想调用 git pull 但它失败了。没有权限。 但是在我从手写命令编写运行“start-ssh-agent.cmd”之后,我调用 git pull 它可以工作。

我的问题是如何修改执行 git pull 然后运行 ​​AutoApp.exe 的批处理文件?

【问题讨论】:

    标签: windows git batch-file ssh cmd


    【解决方案1】:

    我这里有一个小sn-p,可以轻松地以管理员身份运行批处理文件。看看这是否有帮助。

    ::You'll need this because my snippet uses delayedexpansion heavily.
    setlocal enableextensions enabledelayedexpansion
    
    ::Restore running directory. Put this before any file operations. I usually put it near the top.
    if !CD!==%SystemRoot%\system32 pushd %~dp0
    
    ::Put this after where you exit the script.
    :admincheck
    net session > nul 2>&1
    if not %errorlevel%==0 goto continuecheck
    if exist "%temp%\uacprompt*.vbs" (
        del "%temp%\uacprompt*.vbs" > nul 2>&1
        exit /b
    )
    :continuecheck
    ping 127.0.0.1 -n 1 > nul
    net session > nul 2>&1
    if not %errorlevel%==0 goto nouac
    exit /b
    
    :nouac
    call :printui Administrative privileges not found. Requesting...
    ping 127.0.0.1 -n 1 > nul
    
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\uacprompt%instance%.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\uacprompt%instance%.vbs"
    "%temp%\uacprompt%instance%.vbs" > nul 2>&1
    
    ::Check if uacprompt.vbs script exists. VBS script should be deleted when Admin prompt launches.
    ping 127.0.0.1 -n 2 > nul
    if exist "%temp%\uacprompt%instance%.vbs" (
    del "%temp%\uacprompt%instance%.vbs" > nul 2> nul
    echo This script requires Admin privileges to run^^! Exiting...
    ping 127.0.0.1 -n 3 >nul
    exit
    )
    exit
    

    【讨论】:

    • 你能修改我的脚本吗?我尝试了一些此代码的组合,但都失败了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 2019-01-09
    • 2012-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多