【问题标题】:When program uses Command to open Bash to run a script, Bash closes immediately without running the script当程序使用 Command 打开 Bash 运行脚本时,Bash 立即关闭而不运行脚本
【发布时间】:2019-12-11 23:58:55
【问题描述】:

我设置了一个简单的、已经可以使用的 bash 脚本,用于在 Windows 上的游戏前端 EmulationStation 中使用特定程序启动特定文件。

但前端通过命令提示符路由其操作。而当使用 Command 通过 Bash 运行脚本时,Bash shell 只是打开然后立即关闭。

Here's an image of what shows for the instant before Bash closes.

这仅在首先通过单独的命令提示符时才会发生,例如 Windows 命令提示符或 Git 命令提示符。直接通过 git-bash shell 运行带有适当参数的脚本就可以了。

如果您出于任何原因想查看脚本,请点击此处:

#!/bin/bash

defaultemulaunch="V:/Emulation/.emulationstation/systems/retroarch/retroarch.exe -L "V:/Emulation/.emulationstation/systems/retroarch/cores/bsnes_mercury_accuracy_libretro.dll" \"$1\""

emu1names=(\
    "(1999) Fire Emblem - Thracia 776.smc")

emu1launch="V:/Emulation/.emulationstation/systems/retroarch/retroarch.exe -L "V:/Emulation/.emulationstation/systems/retroarch/cores/snes9x_libretro.dll" \"$1\""

gamename=`basename "$1"`
for index in ${!emu1names[*]}
    do
        game=${emu1names[index]}
        if [ "$game" == "$gamename" ]; then
        eval "$emu1launch"
    fi
done

eval "$defaultemulaunch"

但值得指出的是,在从单独的命令提示符启动进程时尝试运行 any bash 脚本时会发生这种情况。

注意: Git 安装在包含仿真前端 (V:) 的硬盘驱动器上——而不是系统操作系统/启动驱动器 (C:) 的用户目录或程序目录中.我之所以提到这一点,是因为 git-bash 在明显的“登录”步骤中失败,除非直接启动,感觉这可能是默认文件路径问题。

【问题讨论】:

    标签: windows bash command-prompt git-bash


    【解决方案1】:

    检查该程序在从 CMD 执行时是否仍会打开/关闭 Windows:

    bash -c '/v/path/to/bash/script'
    

    在你的情况下:

    set PATH=V:\Emulation\
    set GIT_HOME=V:\Emulation\Git
    set PATH=%GIT_HOME%;%GIT_HOME%\bin;%GIT_HOME%\usr\bin;%GIT_HOME%\mingw64\bin;%PATH
    

    然后:

    cd V:/Emulation/.emulationstation/roms/snes/
    bash -c './gamelaunch.sh "./(1990) F-Zero.sfc"'
    

    我通常会制作一个run.bat 脚本:

    • 设置正确的PATH
    • 启动正确的脚本

    这样,对于我的任何项目,我只需键入 run。
    它运行。

    【讨论】:

    • 在这种情况下它不会打开和关闭窗口;尝试这样做会导致 Command 返回“没有这样的文件或目录”错误。
    • @precursormar 你在那个 CMD 中输入了什么命令?对于 bash 程序,我会输入(并且已经做了很多次)bash -c "./my_bash_script_file"
    • 当它立即打开和关闭时,我只是输入如下内容:V:/Emulation/.emulationstation/roms/snes/gamelaunch.sh "V:/Emulation/.emulationstation/roms/snes/(1990) F-Zero.sfc" Windows 将 .sh 文件与 git-bash 相关联,因此它尝试使用 git-bash 运行脚本,但随后Bash shell 关闭。当我输入bash -c "/v/Emulation/.emulationstation/roms/snes/gamelaunch.sh" 的任何变体时,我会返回:/bin/bash: [filepath]: No such file or directory
    • 导致脚本执行它应该做的唯一情况是直接打开 git-bash.exe,并运行类似V:/Emulation/.emulationstation/roms/snes/gamelaunch.sh "V:/Emulation/.emulationstation/roms/snes/(1990) F-Zero.sfc"的命令
    • @precursormar 在 CMD 中尝试相同的 bash -c "...",您首先在其中设置简化的 PATH,如 stackoverflow.com/a/57345422/6309 中所示。
    猜你喜欢
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    相关资源
    最近更新 更多