Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a way to change OS.execute working directory and environment variables #11710

Open
Ryhon0 opened this issue Feb 6, 2025 · 1 comment

Comments

@Ryhon0
Copy link

Ryhon0 commented Feb 6, 2025

Describe the project you are working on

Unofficial mod loader for an existing game made with Godot. When launching the game, a temporary directory with a override.cfg file and main loop script is created, from where the game is ran.

Describe the problem or limitation you are having in your project

OS.execute, execute_with_pipe, create_process and create_instance all lack a way to change the working directory and environment variables of the new process without relying on OS specific shell commands.

See also godotengine/godot#5708

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Adding extra arguments to the mentioned functions would completely fix this issue. The new arguments would default to null. When null, the the child process inherits parent's working dir and enviroment.
Alternatively, a new class containing all the process start info would be created akin to C#'s ProcessStartInfo. It would include the executable path, arguments, working directory, environment variables and pipe configuration.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

The extra arguments way:

create_process("/path/to/my.exe", ["arg1", "arg2"], false, "/my/working/dir", {"MY_ENV": "value"})

The class way:

var start = ProcessStartInfo.new()
start.executable = "/path/to/my.exe"
start.args = ["1","2"]
start.pwd = "/my/working/dir"
start.env = {"MY_ENV": "value"}

var process = start.run()
if process:
   print(process.pid)
else: 
   print("Failed to create process")

If this enhancement will not be used often, can it be worked around with a few lines of script?

This issue can be worked around in C# by using it's process library.
In GDScript, shell commands can be used to change the working directory and environment variables and run the process, but they're OS specific.
sh -c and cmd /C expect the series of commands to be passed as a single argument, requiring escaping logic for paths, environment variables and arguments.
On Linux, sh may link to bash, dash, GNU sh or busybox, potentially leading to inconsistent results.

Is there a reason why this should be core and not an add-on in the asset library?

There's already process start functions in Godot, not having these features severely limits their functionality for specific use cases

@RedMser
Copy link

RedMser commented Feb 7, 2025

Have you seen #5293 already? It mentions a workaround which was enough for me at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants