mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-20 16:20:18 +01:00
On Windows, put commands in a script before executing them
This avoids the problem that newlines in the command always interrupt execution.
This commit is contained in:
parent
251aef245c
commit
0fb30e99ec
1 changed files with 29 additions and 22 deletions
25
shell.gd
25
shell.gd
|
@ -37,7 +37,10 @@ func run(command, crash_on_fail=true):
|
|||
hacky_command += "cd '%s' || exit 1;" % _cwd
|
||||
hacky_command += command
|
||||
|
||||
# Godot's OS.execute wraps each argument in double quotes before executing.
|
||||
var result
|
||||
if _os == "X11" or _os == "OSX":
|
||||
# Godot's OS.execute wraps each argument in double quotes before executing
|
||||
# on Linux and macOS.
|
||||
# Because we want to be in a single-quote context, where nothing is evaluated,
|
||||
# we end those double quotes and start a single quoted string. For each single
|
||||
# quote appearing in our string, we close the single quoted string, and add
|
||||
|
@ -50,22 +53,26 @@ func run(command, crash_on_fail=true):
|
|||
# becomes
|
||||
#
|
||||
# "'test '"'"'fu'"'"' "bla" blubb"
|
||||
#
|
||||
# Quoting Magic is not needed for Windows!
|
||||
if _os == "X11" or _os == "OSX":
|
||||
hacky_command = '"\''+hacky_command.replace("'", "'\"'\"'")+'\'"'
|
||||
|
||||
var result = helpers.exec(_shell_binary(), ["-c", hacky_command], crash_on_fail)
|
||||
exit_code = result["exit_code"]
|
||||
hacky_command = '"\''+hacky_command.replace("'", "'\"'\"'")+'\'"'
|
||||
result = helpers.exec(_shell_binary(), ["-c", hacky_command], crash_on_fail)
|
||||
elif _os == "Windows":
|
||||
# On Windows, if the command contains a newline (even if inside a string),
|
||||
# execution will end. To avoid that, we first write the command to a file,
|
||||
# and run that file with bash.
|
||||
var script_path = game.tmp_prefix_inside + "command"
|
||||
helpers.write_file(script_path, hacky_command)
|
||||
result = helpers.exec(_shell_binary(), [script_path], crash_on_fail)
|
||||
else:
|
||||
helpers.crash("Unimplemented OS: %s" % _os)
|
||||
|
||||
if debug:
|
||||
print(result["output"])
|
||||
|
||||
exit_code = result["exit_code"]
|
||||
return result["output"]
|
||||
|
||||
func _shell_binary():
|
||||
|
||||
|
||||
if _os == "X11" or _os == "OSX":
|
||||
return "bash"
|
||||
elif _os == "Windows":
|
||||
|
|
Loading…
Reference in a new issue