@polygaryd take a look at the script module for minecraft for how to do it. https://github.com/RetroPie/RetroPie-Setup/blob/master/scriptmodules/ports/minecraft.sh