precursormar
precursormar

Reputation: 13

When program uses Command to open Bash to run a script, Bash closes immediately without running the script

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.

Upvotes: 1

Views: 2516

Answers (1)

VonC
VonC

Reputation: 1323753

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.

Upvotes: 1

Related Questions