0

So I'm creating a quick script that basically launches xboxdrv then a game from steam to enable controller support. Yes, while the most games with controller support automatically work with the Xbox 360 controller, there are some games that require you to be running the controller under the xpad driver, else it won't recognize the controller for some reason. The game in question is Bit.Trip Runner 2 on Linux (XUbuntu).

The problem I'm having is trying to get the script to wait for the game to exit (since it gets launched by steam's own commands), and then terminate xboxdrv, to free up memory, but what is happening is when the game exits, I have to go into the terminal and hit Ctrl+C in order to move it along.

If possible, please explain in layman's terms, because this is my first full out batch scrpt for linux. Below is the script in question:

sudo --validate
sudo xboxdrv --silent --detach-kernel-driver --mimic-xpad --dbus session & sleep 2
steam steam://rungameid/$APPID #<-- I want the game to exit to then kill xboxdrv
wait -n $!  #<-- If I don't put wait, it will immediately kill xboxdrv after the game launches
sudo killall xboxdrv
exit 0
  • 2
    Welcome to StackOverflow. It's probably best if you can trim down your (otherwise complete) shell script to just a few lines that aren't doing what you want them to. That way you'll get more people interested in helping you. – O. Jones Oct 21 '14 at 06:49
  • 1
    Yeah, sorry about that. I was half asleep when I posted this question. Just wondering, would it work if I used *pgrep* to search for the process's pod and then tell *wait* to wait on that ID? – Tech0verlord Oct 21 '14 at 10:00

1 Answers1

1

Well, it seems like the issue was that wait wasn't applying properly, something about child processes. If it wasn't that it was waiting on xboxrdv, it was that it couldn't apply itself properly. After doing a bit more looking around, I happened upon this question, which gave me the code I needed for the wait. So what I ended up doing was adding that bit of code along with a pgrep -x command, so that it could grab and wait on the proper pid.

So in the end, the important part code ended up looking like this:

if [ "$GAMENAME" = "BTR2" ] || [ "$GAMENAME" = "Runner 2" ]; then
    APPID=218060
    GameProc=[r]unner2
fi

sudo --validate
sudo xboxdrv --silent --quiet --detach-kernel-driver --mimic-xpad --dbus session & sleep 2
steam steam://rungameid/$APPID & sleep 20

check_run_and_grab(){
if ps aux | grep "$GameProc" > /dev/null
    then
        GamePID=$(pgrep -x "$GameProc")
        while kill -0 "$GamePID";do
            sleep 5
        done
        sudo killall xboxdrv
        exit 0
    else
        echo "Game process not found, waiting 5 seconds and trying again"
        sleep 5
        check_run_and_grab
fi
}

check_run_and_grab

To me, the only thing that would make this better is if it didn't care for capitalization for the game argument (first if statement).

Community
  • 1
  • 1