2020-01-29 20:25:13 +01:00
|
|
|
extends Node
|
|
|
|
|
2020-09-08 16:00:18 +02:00
|
|
|
var cwd
|
2020-01-29 20:25:13 +01:00
|
|
|
|
|
|
|
func _ready():
|
2020-09-08 16:00:18 +02:00
|
|
|
cwd = exec("pwd", [], true)
|
2020-09-01 19:20:51 +02:00
|
|
|
|
2020-09-08 16:00:18 +02:00
|
|
|
# Run a simple command with arguments, blocking, using OS.execute.
|
|
|
|
func exec(command, args=[], remote_trailing_newline=false):
|
|
|
|
var debug = false
|
|
|
|
if debug:
|
|
|
|
print("game.exec: %s [%s]" % [command, PoolStringArray(args).join(", ")])
|
|
|
|
|
2020-09-04 14:57:37 +02:00
|
|
|
var output = []
|
2020-09-08 16:00:18 +02:00
|
|
|
OS.execute(command, args, true, output, true)
|
|
|
|
output = output[0]
|
2020-09-04 14:57:37 +02:00
|
|
|
|
2020-09-08 16:00:18 +02:00
|
|
|
if debug:
|
|
|
|
print(output)
|
2020-09-04 14:57:37 +02:00
|
|
|
|
2020-09-08 16:00:18 +02:00
|
|
|
if remote_trailing_newline:
|
|
|
|
output = output.substr(0,len(output)-1)
|
|
|
|
|
|
|
|
return output
|
2020-09-01 19:20:51 +02:00
|
|
|
|
|
|
|
func read_file(path):
|
2020-09-04 14:57:37 +02:00
|
|
|
print("read "+path)
|
|
|
|
var file = File.new()
|
|
|
|
file.open(path, File.READ)
|
|
|
|
var content = file.get_as_text()
|
|
|
|
file.close()
|
|
|
|
return content
|
2020-09-01 19:20:51 +02:00
|
|
|
|
|
|
|
func write_file(path, content):
|
2020-09-04 14:57:37 +02:00
|
|
|
var file = File.new()
|
|
|
|
file.open(path, File.WRITE)
|
|
|
|
file.store_string(content)
|
|
|
|
file.close()
|
|
|
|
return true
|