Problems when starting emulationstation from a script

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

This topic contains 9 replies, has 2 voices, and was last updated by  petrockblog 2 years, 4 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
  • #104998


    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 with the following content:


    I then execute this script:
    $ 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?



    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)



    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.



    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.



    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.



    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.



    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 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.



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



    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/ > /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/ line 667: /dev/tty: No such device or address
    /opt/retropie/supplementary/runcommand/ line 696: /dev/tty: No such device or address
    Traceback (most recent call last):
      File "/opt/retropie/supplementary/runcommand/", 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/ < /dev/tty > /dev/tty
    @reboot bash /home/pi/ > /dev/tty
    @reboot bash /home/pi/ > /dev/tty0



    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/



    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/ > /home/pi/media_output.log 2>&1" 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

PLEASE NOTE: All orders that are placed between January 14th and January 28th will be shipped on January 29th. Dismiss