0 votes

Hello, I am running a simple self-closing action via ui_input spacebar, using OS.execute, and was wondering if my syntax was correct to send this command to the terminal/console of the OS:

ps -ef | awk '/godot-engine/ {print $2}' | xargs kill

the way I have it (tested that the input works, and it does, via a pop-up sprite visible=true on spacebar press) is as follows:

func _on_DisplayAlert_pressed():
var output = []
#var Pvariables = "-ef | awk '/tester/ {print $2}' | xargs kill"
OS.execute("ps", ["-ef", "|", "awk", "'/tester/ {print $2}'", "|", "xargs", "kill"], true, output)

the Pvariables was a test to see if it needed to be one string, but the action seems to be doing nothing, I tried it on a windows OS with CD and START commands and it operated after export, what could I be doing wrong?

Thank you!

Godot version 3.3.4
in Engine by (14 points)

1 Answer

0 votes

So you're asking a game engine to do complex tasks with unrelated syntax ....... hmm nothing can possibly go wrong here and debugging won't be a nightmare with the more you will later need to add.


Use scripts for such tasks with the native console

OS.execute("bash", ["my_complicated.sh", "param1"])

#Another Example
OS.execute("cmd", ["my_complicated.bat", "param2"])

#Another other Example
OS.execute("python", ["my_complicated.py", "param3"])
by (5,020 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.