Python sh: 0 can't open

I’m working on a new snap using a python3 script that calls on some bash scripts to run minecraft server from a menu.

Here’s the thing, and it’s probably obvious to many of you, I can’t get it to run inside my snap. I’ve tried several ways of calling the same commands in the snap (via the script) and I keep getting the same error listed above. Here’s the current snapcraft.yaml:

name: mc-server-installer
version: git
summary: Minecraft Server Downloader and Installer
description: |
    A Minecraft Server installer snap.  
grade: stable
confinement: strict

apps:
  mc-server-installer:
    command: python3 $SNAP/server-installer-menu.py
    plugs:
      - network
      - home
      - network-bind

parts:
  mc-server-installer:
    source: https://github.com/kz6fittycent/mc-server-installer
    source-type: git
    plugin: python
    python-version: python3
    
    build-packages:
      - openjdk-8-jre-headless
      - wget
      - python3
      
    stage-packages:
      - openjdk-8-jre-headless
      - wget
      - python3

  publish:
    plugin: copy
    files:
      ./2.sh: 2.sh
      ./4.sh: 4.sh
      ./6.sh: 6.sh
      ./8.sh: 8.sh
      ./12.sh: 12.sh
      ./16.sh: 16.sh
      ./24.sh: 24.sh
      ./server-installer-menu.py: server-installer-menu.py

Here’s the python script (menu):

#!/usr/bin/env python3

import subprocess
import time
import os
import sys
 
print()
def print_menu():       
    print (20 * "-" , "MC-SERVER-INSTALLER MENU" , 20 * "-")
    print ()
    print ("Choose the amount of RAM you need: ")
    print ()
    print ("1. 2GB Max allotment")
    print ("2. 4GB Max allotment")
    print ("3. 6GB Max allotment")
    print ("4. 8GB Max allotment")
    print ("5. 12GB Max allotment")
    print ("6. 16GB Max allotment")
    print ("7. 24GB Max allotment")
    print ("8. Exit")
    print ()
    print (67 * "-")
    print ()
  
loop=True      
  
while loop:
    print_menu()
    choice = str(input("Enter your choice: "))
    
    choice = int(choice)
    
    if choice == 1:     
        print ("Starting server with 2GB max...")
        subprocess.call(['sh','$SNAP/2.sh'])
    elif choice == 2:
        print ("Starting server with 4GB max...")
    elif choice == 3:
        print ("Starting server with 6GB max...")
        subprocess.call(['sh','$SNAP/6.sh'])
    elif choice == 4:
        print ("Starting server with 8GB max...")
        subprocess.call(['sh','$SNAP/8.sh'])
    elif choice == 5:
        print ("Starting server with 12GB max...")
        subprocess.call(['sh','$SNAP/12.sh'])
    elif choice == 6:
        print ("Starting server with 16GB max...")
        subprocess.call(['sh','$SNAP/16.sh'])
    elif choice == 7:
        print ("Starting server with 24GB max...")
    elif choice == 8:
        print ("Exiting. Goodbye!")
        
        loop=False 
    else:
        print("Invalid choice, please choose a menu item.")

Any help is very much appreciated. I am so close to setting this snap free…I can feel it! :wink:

python will not know what $SNAP, you need to expand the variable for it to be resolved.

Even if the file structure is flat? All the scripts being called are in the same directory as the python menu. That’s what is confusing me a bit. I can run the same script(s) on my local system w/o error from the same directory. This version of the script shown is the last I had tried. Previously, $SNAP was omitted from the path.

So it looked like: subprocess.call(['sh','16.sh'])

You’ll have to pardon my ignorance, I’m still learning.

why call python3 in the command stanza at all if you already have a hashbang inside the application anyway … I’d just make server-installer-menu.py executable and drop the python3 call from the command: line …

use os.environ['SNAP'] to get $SNAP

1 Like

Thanks to all of you for your input. I switched to bash and it’s working as intended.