RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Runcommand usage from python script not working

    Scheduled Pinned Locked Moved Ideas and Development
    runcommandpythonraspbian
    7 Posts 3 Posters 734 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      MEsyM
      last edited by

      Hello, noobie here.

      Im trying to use runcommand to start snes game from python script on rapsbian. I am using popen for it with no luck. When i use popen for dosbox it opens new terminal window and starts the game given from argument. When i hry to start runcommand no error is given but nothing happens.

      Can anyone give advise or post working code example.

      1 Reply Last reply Reply Quote 0
      • mituM
        mitu Global Moderator
        last edited by

        I think it's you that has to show some code here to show how are you calling runcommand. Paste the relevant code in code blocks and some context of how you call the python script.

        1 Reply Last reply Reply Quote 0
        • M
          MEsyM
          last edited by MEsyM

          Sorry...

          heres my code... Iam building custom GUI with tkinter. However this is my whole code for testing in single test.py file, and does nothing when run via IDE nor via terminal python test.py. When I run the cmd itself from terminal it starts the game. If I run it from test.py it does nothing at all, but doesnt even throw exception or nothing.

          cmd = "/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ snes '/home/pi/RetroPie/roms/snes/Super_Mario.smc'"
          
          process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
          outout, error = process.communicate()
          
          while 1:
           print(output)
           print(error)
          
          

          prints looks as:
          b''
          None

          • when I enter wrong path to rom it gives no such file found error, so it does something :)

          ive tryed with shell=True and many other options. this is just my last one

          1 Reply Last reply Reply Quote 0
          • mituM
            mitu Global Moderator
            last edited by mitu

            Hm, one thing that I notice is that split doesn't un-quote the last parameter (the ROM path) and the path still contains '. Plus, if the ROM path contains spaces, then split will mess it up. Here's an example using the ROM name "True Lies (USA).zip"

            Parameters:
            Executing: /opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-snes9x2010/snes9x2010_libretro.so --config /opt/retropie/configs/snes/retroarch.cfg "'/home/pi/RetroPie/roms/snes/True" --appendconfig /dev/shm/retroarch.cfg
            
            Failed to open '/home/pi/RetroPie/roms/snes/True: No such file or directory
            

            I think you should manually create the 1st argument to Popen and not rely on split to generate a correct list of arguments.

            1 Reply Last reply Reply Quote 0
            • cyperghostC
              cyperghost
              last edited by

              I would suggest

              p = subprocess.Popen(['/opt/retropie/supplementary/runcommand/runcommand.sh','0', '_SYS_', 'snes', '/home/pi/RetroPie/roms/snes/Super_Mario.smc'])
              
              M 1 Reply Last reply Reply Quote 0
              • M
                MEsyM @cyperghost
                last edited by

                @cyperghost said in Runcommand usage from python script not working:

                p = subprocess.Popen(['/opt/retropie/supplementary/runcommand/runcommand.sh','0', 'SYS', 'snes', '/home/pi/RetroPie/roms/snes/Super_Mario.smc'])

                I've tried that. Does the same thing but the prints changed to:

                None
                None
                ...

                cyperghostC 1 Reply Last reply Reply Quote 0
                • cyperghostC
                  cyperghost @MEsyM
                  last edited by

                  @mesym Well I don't know what's wrong but this worked for me. It starts Tetris and shows me pointer adress. Something wrong with your py-fu?

                  import os
                  import time
                  import subprocess
                  
                  p = subprocess.Popen(['/opt/retropie/supplementary/runcommand/runcommand.sh','0', '_SYS_', 'gb', '/home/pi/RetroPie/roms/gb/Tetris (JUE) (V1.0) [!].gb'])
                  
                  while 1:
                   print(p)
                   time.sleep(5)
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  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.