1
0
Fork 0
forked from fun/fun

Added proc_run() and system() for processes and added to stdlib as class. (0.16.6)

This commit is contained in:
Johannes Findeisen 2025-10-02 01:50:53 +02:00
commit 1ac163a01e
11 changed files with 253 additions and 17 deletions

60
examples/process_example.fun Executable file
View file

@ -0,0 +1,60 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://hanez.org/project/fun/
*
* Copyright 2025 Johannes Findeisen
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2025-10-02
*/
/*
* Subprocess example using proc_run/system and the Process class.
*/
#include <io/process.fun>
print("=== Built-ins ===")
r = proc_run("echo Hello from Fun")
print(r["out"])
print(join(["exit code: ", to_string(r["code"])], ""))
code = system("sh -c 'exit 3'")
print(join(["system() exit code: ", to_string(code)], ""))
print("=== Process class ===")
p = Process()
res = p.run("uname -s")
print(join(["OS: ", res["out"]], ""))
res2 = p.run_merge_stderr("sh -c 'echo out; echo err 1>&2; exit 1'")
print("merged output:")
print(res2["out"])
print(join(["exit code: ", to_string(res2["code"])], ""))
ok = p.check_call("true")
print(join(["check_call(true): ", to_string(ok)], ""))
ok2 = p.check_call("false")
print(join(["check_call(false): ", to_string(ok2)], ""))
/* Expected output:
=== Built-ins ===
Hello from Fun
exit code: 0
system() exit code: 3
=== Process class ===
OS: Linux
merged output:
out
err
exit code: 1
check_call(true): 1
check_call(false): 0
*/