How to launch emulation station in Python script?
-
What is the correct way to launch emulation station from a Python script? If I'm at the terminal I can just type "emulationstation" and hit enter. But I don't know the correct syntax to launch from a script. I've tried variations of os.system("emulationstation") but it doesn't work correctly. There has to be a way, but I am a beginner and cannot find any answers despite lots of searching. Anyone know the answer?
-
import subprocess
subprocess.call("emulationstation", shell=True)
-
When I do that I get an error:
"emulationstation should not be run as root. If you used 'sudo emulationstation' please run without sudo"As far as I know, I am not using 'sudo emulationstation'.
Below is the code in case you'd like to see. I am triggering the code to run at boot with this line in the rc.local file:
python /home/pi/randomSimpsons.py &
#!/usr/bin/env python2.7 # main script by Alex Eames http://RasPi.tv # http://RasPi.tv/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio-part-3 import RPi.GPIO as GPIO import time import os import random import subprocess directory = "/home/pi/simpsons/" redirectory = "/home/pi/" GPIO.setmode(GPIO.BCM) # GPIO 27 & 17 set up as inputs, pulled up to avoid false detection. # Both ports are wired to connect to GND on button press. # So we'll be setting up falling edge detection for both GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) # GPIO 3 set up as an input, pulled UP GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP) #this callback closes emulationstation and runs a random video from the directory specified #structure of random episode code is taken from Stephen Coyle's project here: http://stephencoyle.net/software/randomSimpsons.py def my_callback(channel): episode = random.choice(os.listdir(directory)) cmd = "nohup omxplayer -b -o hdmi " + "'" + directory + episode + "' &" os.system("killall emulationstation") os.system('killall omxplayer.bin') os.system(cmd) #this callback closes omxplayer and restarts emulationstation def my_callback2(channel): print("test1") os.system('killall omxplayer.bin') print("test2") cmd2 = "nohup emulationstation " + "'" + redirectory + "' &" # os.system("emulationstation") # os.system(cmd2) subprocess.call("emulationstation", shell=True) print("test3") GPIO.add_event_detect(17, GPIO.FALLING, callback=my_callback, bouncetime=300) GPIO.add_event_detect(27, GPIO.FALLING, callback=my_callback2, bouncetime=300) try: GPIO.wait_for_edge(3, GPIO.FALLING) print("self destruct initiated") os.system("sudo shutdown -h now") #os.system('sudo python /home/pi/randomSimpsons.py') # point this to the location of this file except KeyboardInterrupt: GPIO.cleanup() # clean up GPIO on CTRL+C exit GPIO.cleanup() # clean up GPIO on normal exit
-
@gryffin13 said in How to launch emulation station in Python script?:
cmd2 = "nohup emulationstation " + "'" + redirectory + "' &"
What's this line for?
-
@geneworld
That was a variable in one of my previous methods I tried. The line that called it (os.system(cmd2)) is commented out below. -
/etc/rc.local
is executed as root.You can't launch ES for retropie that way - as it needs to be attached to a TTY. You could try launching your script from the
/opt/retropie/configs/all/autostart.sh
though. -
@buzz
Ok I'm a Linux beginner and I guess I didn't understand that it was executed as root. I'll try your suggestion and see if that works for me. Thanks.Also for my own education - what does "attached to a TTY" mean?
-
@gryffin13 attached to a terminal rather than in the background - as runcommand needs to capture input and output to the terminal etc.
-
@buzz
Sorry for the long delay - I was prevented from working on this. When I did get around to it though, I was able to use this advice to come up with a solution. Thanks a bunch!
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.