I run linux first off

I keep trying to run a python file with this command: OS.execute( 'sudo python3 test.py', [], true, output ) But it outputs nothing! It works perfectly fine when running ls command it outputs correctly.

if u could tell me if there is a way to run my python script.

ive even tried OS.execute( 'sudo gnome-terminal python3 test.py', [], true, output ) which is supposed to open a new terminal window and run it but it doesnt work

Plz help

Arguments should go into the second parameter of execute. The first parameter should only be the actual command that is executed.

I could not get sudo elevation to work, but in any case it's probably best to confirm that python works first and worry about elevation after.

Try the following:

var output = []
OS.execute('python3', ['--version'], true, output) 
print(output)

The output for me is:

[Python 3.8.2
]

If that works then you should be able to replace --version with the path to your python file.

So back to sudo - If you can get python3 to execute a script without sudo, I would use that script to do the sudo elevation in a proper python subprocess rather than Godot.

Wouldn't you run godot with elevated privileges and then call python without sudo?

@bitshift-r said: Arguments should go into the second parameter of execute. The first parameter should only be the actual command that is executed.

I could not get sudo elevation to work, but in any case it's probably best to confirm that python works first and worry about elevation after.

Try the following:

var output = []
OS.execute('python3', ['--version'], true, output) 
print(output)

The output for me is:

[Python 3.8.2
]

If that works then you should be able to replace --version with the path to your python file.

So back to sudo - If you can get python3 to execute a script without sudo, I would use that script to do the sudo elevation in a proper python subprocess rather than Godot.

Ok so i tried it and i just outputs an empty array :( ill keep looking for reasons why this might be happening since it worked for you. It seems like only some commands work for me ill try running it with elevated priiligies to

@bitshift-r said: Arguments should go into the second parameter of execute. The first parameter should only be the actual command that is executed.

I could not get sudo elevation to work, but in any case it's probably best to confirm that python works first and worry about elevation after.

Try the following:

var output = []
OS.execute('python3', ['--version'], true, output) 
print(output)

The output for me is:

[Python 3.8.2
]

If that works then you should be able to replace --version with the path to your python file.

So back to sudo - If you can get python3 to execute a script without sudo, I would use that script to do the sudo elevation in a proper python subprocess rather than Godot.

I updated the version of godot i was using the one from the ubuntu store and now it works

8 months later

@UnknownUser said:

@bitshift-r said: Arguments should go into the second parameter of execute. The first parameter should only be the actual command that is executed.

I could not get sudo elevation to work, but in any case it's probably best to confirm that python works first and worry about elevation after.

Try the following:

var output = []
OS.execute('python3', ['--version'], true, output) 
print(output)

The output for me is:

[Python 3.8.2
]

If that works then you should be able to replace --version with the path to your python file.

So back to sudo - If you can get python3 to execute a script without sudo, I would use that script to do the sudo elevation in a proper python subprocess rather than Godot.

I updated the version of godot i was using the one from the ubuntu store and now it works

what version of Godot did it work?

OK, I'm back and I found 'A' solution (it's not the best but hey it's lazy and works like a charm). I used the OS.execute() to run a shell script to run my python code. I can even interact with conda and switch environments to run my object detection AI XD.

4 months later
var PID = OS.execute("sudo", ["/usr/local/bin/python3.9",  "PathToScript.py"], false)
	OS.execute(str(PID), ["my_password"])

This works for me, but note that it is obviously dangerous to just put the password in the .gd file.

a year later