1

I have a simple, already-working bash script set up to launch specific files with specific programs in the gaming frontend EmulationStation on Windows.

But the frontend routes its actions through a Command Prompt. And when Command is used to run the script through Bash, the Bash shell just opens and then closes immediately.

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

This is only happening when going through a separate Command Prompt first, such as Windows Command Prompt or Git Command Prompt. Running the script with an appropriate argument directly through the git-bash shell works just fine.

In case you want to see the script for any reason, here it is:

#!/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"

But it's worth pointing out that this is happening when trying to run any bash script when starting the process from a separate Command Prompt.

Note: Git is installed on the hard drive that houses the emulation frontend (V:)---not in the user directory or programs directory of the system's OS/boot drive (C:). I mention this because git-bash's failure at an apparent "login" step except when launched directly feels like it could be a default filepath issue.

1 Answers1

1

Check if that program would still open/close a Windows when executed from the CMD with:

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

In your case:

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

Then:

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

I usually make a run.bat script which would:

  • set the correct PATH
  • launch the correct script

That way, for any of my project, I just type run.
And it runs.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • It does not open and close a window in that situation; trying that instead causes Command to return a "No such file or directory" error. – precursormar Aug 05 '19 at 20:40
  • @precursormar What command do you type in that CMD? For a bash program, I would type (and have done so many time) `bash -c "./my_bash_script_file"` – VonC Aug 05 '19 at 20:45
  • When it opens and close immediately, I am just typing in something like: ````V:/Emulation/.emulationstation/roms/snes/gamelaunch.sh "V:/Emulation/.emulationstation/roms/snes/(1990) F-Zero.sfc"```` Windows associates .sh files with git-bash, so it attempts to run the script with git-bash, but then the Bash shell closes. When I type any variant of ````bash -c "/v/Emulation/.emulationstation/roms/snes/gamelaunch.sh"````, I get back: ````/bin/bash:```` [filepath]````: No such file or directory```` – precursormar Aug 05 '19 at 20:57
  • The only situation that results in the script doing what it's supposed to do is by opening git-bash.exe directly, and running a command like ````V:/Emulation/.emulationstation/roms/snes/gamelaunch.sh "V:/Emulation/.emulationstation/roms/snes/(1990) F-Zero.sfc"```` – precursormar Aug 05 '19 at 20:59
  • @precursormar TRy the same `bash -c "..."` in a CMD where you set first a simplified PATH, as seen in https://stackoverflow.com/a/57345422/6309. – VonC Aug 05 '19 at 21:01
  • Okay, I've just tried ````set PATH=V:\Emulation\````, ````set GIT_HOME=V:\Emulation\Git````, and ````set PATH=%GIT_HOME%;%GIT_HOME%\bin;%GIT_HOME%\usr\bin;%GIT_HOME%\mingw64\bin;%PATH%````. Then I ran the same command. This time nothing happened at all: no error message, and no window pop-up. Did I set the PATH variable incorrectly? – precursormar Aug 05 '19 at 21:16
  • @precursormar PATH looks good. I don't know what command you typed though. I would cd to the right folder, and type `bash -c "./my_bash_script_file"`, with `./` meaning look for the script in the current folder. – VonC Aug 05 '19 at 21:19
  • Okay, that worked! After settings those temporary variable changes and navigating to any part of the V:, the script properly executes with the command ````bash -c './gamelaunch.sh "./(1990) F-Zero.sfc"'```` Does that mean I should permanently add those PATH parameters to fix this? – precursormar Aug 05 '19 at 21:25
  • @precursormar Great! Well done. See my edited answer: I prefer using a wrapper instead of modifying the PATH at a global Windows level. – VonC Aug 05 '19 at 21:29
  • That works! Thank you very much for your assistance! But you'll need to edit the ````"./gamelaunch.sh "./(1990) F-Zero.sfc"```` to ````'./gamelaunch.sh "./(1990) F-Zero.sfc"'```` in your example, otherwise the quotation marks cause a syntax error. (I was going to make the edit myself, but Stack Overflow won't let me because it's less than 6 characters of change.) – precursormar Aug 05 '19 at 21:37
  • @precursormar You are most welcome. I have edited the command accordingly. – VonC Aug 05 '19 at 21:39