Problems when starting emulationstation from a script

Home Forums RetroPie Project Everything else related to the RetroPie Project Problems when starting emulationstation from a script

RetroPie has a new website and forum. Please visit https://retropie.org.uk/ for the new site. The new forum is located at https://retropie.org.uk/forum/. This forum is left here as a read-only archive.

This topic contains 9 replies, has 2 voices, and was last updated by Profile photo of buzz buzz 1 year, 7 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #104998
    Profile photo of thehoff
    thehoff
    Participant

    Hi all,

    I’m experiencing an odd issue with psx/emulationstation. Whenever I start emulation station directly from the command line (through SSH on my pc) everything works fine:
    $ emulationstation
    However, when I start it through a homemade script the games from the psx emulator (and likely also all other emulators) won’t load. The screen will just go black for a few seconds and return to the emulator menu. I’ve made a very simple example in which it fails. A script called emulation.sh with the following content:

    #!bin/sh
    /usr/bin/emulationstation
    

    I then execute this script:
    $ sh emulation.sh

    Additional information:
    Pi Model: 2B
    Built from: binary
    Retropie version used: I suppose it’s version 3.0 since I’ve downloaded and ran the script just 2 days ago.
    USB devices connected: 2TB external harddisk, 2 usb playstation controllers
    controller used: playstation controller
    Error messages received: None

    I have absolutely no clue what could possibly go wrong at this point. Any advice on what to look for?

    • This topic was modified 1 year, 7 months ago by Profile photo of thehoff thehoff.

    #105063
    Profile photo of buzz
    buzz
    Keymaster

    your script is missing a slash (/bin/sh instead of bin/sh). Nothing logged in /tmp/runcommand.log ?

    In case it’s related to the shell, does it make any difference if you use /bin/bash instead (rather than /bin/sh which is dash)

    #105064
    Profile photo of buzz
    buzz
    Keymaster

    or launch it with bash scriptname – no point adding #!/bin/sh etc if going to launch via shell manually. just chmod u+x and launch without.

    #105073
    Profile photo of thehoff
    thehoff
    Participant

    I don’t think the problem is related to the missing ‘/’. Emulationstation does start, so the script is executed properly. Furthermore, /usr/bin/emulationstation was part of a more complex script which did include the missing ‘/’ at the beginning of the script. I’ve also tried running it as both user ‘pi’ and as root.

    Launching the script with bash instead of sh (and changing /bin/sh to bin/bash) did not make any difference. Emulationstation would launch properly, but the emulator would not.

    #105097
    Profile photo of buzz
    buzz
    Keymaster

    as i said, you were launching the script manually via “sh script” so the first line is ignored. No point adding it at all if launching like that, but if you wanted to make it executable it needing fixing.

    don’t run it as root, ES / our launcher script is not designed to be run as root (only the setup script).

    you didn’t answer if there was anything saved in /tmp/runcommand.log

    when you launch emulation station normally, it is actually launched from a script (in /usr/bin/emulationstation), so not sure what your problem might be. You are running on the system directly and not over ssh right ? Try launching from the pi itself – it’s not designed to be launched over ssh.

    • This reply was modified 1 year, 7 months ago by Profile photo of buzz buzz.
    • This reply was modified 1 year, 7 months ago by Profile photo of buzz buzz.
    • This reply was modified 1 year, 7 months ago by Profile photo of buzz buzz.
    #105156
    Profile photo of thehoff
    thehoff
    Participant

    I’ve tried out a few more ways to start emulationstation. All commands are ran as user ‘pi’. I hope this gives you some more clarity:
    start emulationstation locally from the commandline: Works fine. An empty runcommand.log is created at /tmp/. This is the only way I’ve seen a logfile being created.

    Start emulationstation through SSH from my PC: Works fine.

    Start emulationstation through SSH from a script using either bash or sh: Seems to work fine now, not sure if this was the case before.

    Use Crontab to start emulationstation at boot: Black screen for few seconds, then returns to home menu.

    Use Crontab to start a script to start emulationstation: Black screen for few seconds, then returns to home menu.

    Use Crontab to start a script that sleeps for 60 seconds and then starts emulationstation: Black screen for few seconds, then returns to home menu.

    Use add-on “Advanced Launcher” within Kodi to start emulationstation: Black screen for few seconds, then returns to home menu. Please note that this is the way I intent to start emulationstation. But any work-around would also be appreciated.

    • This reply was modified 1 year, 7 months ago by Profile photo of thehoff thehoff.
    • This reply was modified 1 year, 7 months ago by Profile photo of thehoff thehoff.
    • This reply was modified 1 year, 7 months ago by Profile photo of thehoff thehoff.
    #105163
    Profile photo of buzz
    buzz
    Keymaster

    likely due to it not being attached to a TTY when launching via the other methods.

    you could try adding

    
    </dev/tty >/dev/tty
    

    to it perhaps.

    You can add extra logging to runcommand.sh by putting set -x at the top of the script (and perhaps adjust ES launching of it it to redirect all output to a file).

    I can’t advise further without you producing some logs.

    • This reply was modified 1 year, 7 months ago by Profile photo of buzz buzz.
    • This reply was modified 1 year, 7 months ago by Profile photo of buzz buzz.
    • This reply was modified 1 year, 7 months ago by Profile photo of buzz buzz.
    • This reply was modified 1 year, 7 months ago by Profile photo of buzz buzz.
    #105169
    Profile photo of buzz
    buzz
    Keymaster

    and make sure you are launching es from the binary directly and not our launch script to rule anything in that out.

    #105191
    Profile photo of thehoff
    thehoff
    Participant

    It does indeed seem to have something to do with not being attached to a TTY. I added the following line to crontab:

    @reboot bash /home/pi/emulation.sh > /home/pi/output.log 2>&1
    

    When I try to enter a game in psx in emulationstation I get the following output in output.log:

    TERM environment variable not set.
    Press a key (or joypad button 0) to configure launch options for emulator/port (lr-pcsx-rearmed). Errors will be logged to /tmp/runcommand.log
    /opt/retropie/supplementary/runcommand/runcommand.sh: line 667: /dev/tty: No such device or address
    /opt/retropie/supplementary/runcommand/runcommand.sh: line 696: /dev/tty: No such device or address
    Traceback (most recent call last):
      File "/opt/retropie/supplementary/runcommand/joy2key.py", line 43, in <module>
        tty_fd = open("/dev/tty", "w")
    IOError: [Errno 6] No such device or address: '/dev/tty'
    

    Now, I do not know how to attach this process to a tty. Could you supply me with the correct commands? In crontab I tried:
    @reboot bash /home/pi/emulation.sh < /dev/tty > /dev/tty
    @reboot bash /home/pi/emulation.sh > /dev/tty
    @reboot bash /home/pi/emulation.sh > /dev/tty0

    • This reply was modified 1 year, 7 months ago by Profile photo of thehoff thehoff.
    #105194
    Profile photo of buzz
    buzz
    Keymaster

    I don’t think it will work without a controlling terminal as /dev/tty wont exist. I don’t really have time to dig further – runcommand requires that a controlling terminal exists. It’s not going to work from cron – if kodi is launched from terminal then it should be possible to get it to work – but I wouldn’t bother with the cron launching. if you are launching kodi that way, that will not work either

    we launch emulation station from /etc/profile.d/

    #105212
    Profile photo of thehoff
    thehoff
    Participant

    It took a while, but I’ve found an acceptable solution. The program script allows me to circumvent the non-existing tty problem. crontab now contains the following line:
    @reboot script -c "bash /home/pi/startup_script.sh > /home/pi/media_output.log 2>&1"

    startup_script.sh is a script that frequently polls whether my TV is on or not and checks a file for what program it should start when this is the case (currently limited to Kodi and Retropie).

    Thanks for your help!

Viewing 11 posts - 1 through 11 (of 11 total)

Forums are currently read only - please visit the new RetroPie forums at https://retropie.org.uk/forums/

Skip to toolbar