简体   繁体   中英

Python Input Function Crashes Ubuntu Terminal When Run As a .desktop File

I have a.desktop file set up so that I can run my python program to easily run my hosted servers, but when I run the program after I specify the game the terminal crashes.

Ubuntu Version 20.04 Python Version 3.10.6

Python Code:

import os


sv = int(input("Run What Server?\n1) Minecraft\n2) Garry's Mod\n"))
game = ""

try:
    if (sv == 1):
        game = "Minecraft"
    
    elif (sv == 2):
        game = "Garry's Mod"
    
except ValueError:
    print("invalid choice")
    exit(0)

print("Opening " + game + "...")

if (game == "Minecraft"):
    os.system("cd Servers/Minecraft && ./run.sh")
    
elif (game == "Garry's Mod"):
    os.system("cd Servers/Gmod && ./run.sh")

.desktop File:

#!/usr/bin/bash python3
[Desktop Entry]
Version=1.0
Name=Server Launcher
Type=Application
Exec=python3 /home/yomie/.local/share/applications/Servers.py
Terminal=true

Things I have tried:

  • Builtins package
  • Reinstalling Ubuntu completely
  • Updating and Upgrading
  • Reinstalling Python 3.10.6
  • Updating to Python 3.11
  • Changing /usr/bin/gnome-terminal to use 3.11, 3.10.6, 3.10, and 3.8

The only solution I have found to this problem is rewriting the code into another language.

I rewrote mine in C++ and now it suddenly works!

Edit: If I find a solution to this problem that isn't rewriting code I will post it here!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM