fabioz / PyDev.Debugger

Sources for the debugger used in PyDev, PyCharm and VSCode Python
Eclipse Public License 1.0
425 stars 122 forks source link

really like PyDev but how to debug python programs that need root? #282

Closed UltimateSolar closed 3 months ago

UltimateSolar commented 3 months ago

Hello,

really like PyDev thanks for all the hard work and dedication, thinking about patreon Friend membership :+1:

because of lack of forum, a more general question: but how to use PyDev in eclipse to debug python programs that need root functionality? (like list logical volumes (lvdisplay) or meassure socket performance?)

or would it be better to run a separate bash script, that repeatedly reads those values as root and writes them to a temporary text file, where python can pick it up? (probably better approach)

thanks

PS: via subprocess would like to send some commands to postgres, but that actually would require root consider this working script, which tries to interact with postgres + avoiding pip packages (works as root, as non-root it hangs indefinately):

import subprocess

def execute_postgres_command():
    try:
        # Command to execute
        command = 'su - postgres -c "psql -c \\"SELECT version();\\""'

        # Execute the command using subprocess
        result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

        # Check if the command was successful
        if result.returncode == 0:
            # Print or process the output
            print(result.stdout)
        else:
            # Print the error message if command failed
            print(f"Error: {result.stderr}")
    except FileNotFoundError:
        print("su command not found. Make sure your environment supports this command.")

# Call the function to execute the command
UltimateSolar commented 3 months ago

ok found the solution here https://dwaves.de/2024/01/23/gnu-linux-debian-ubuntu-how-to-setup-eclipse-python-development-ide-pydev-in-2024-including-step-debugging-and-all-how-to-debu-python-that-needs-root-how-to-run-eclipse-as-root/

fabioz commented 3 months ago

Great that you've been able to sort it out :)