Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-std

Source of release 0.7.4

0.7.4 / tests / luce_process / main.luc

# process: running a program to completion, a background command waited for, environment
# variables and the working directory. The child is always `sh`: Windows has no `echo`
# program on PATH outside Git's bash.
from luce_std import paths, process

pub func main(arguments: list[str]) -> int!:
    let done = process.run("sh", ["-c", "echo out; echo err 1>&2; exit 3"])
    print(done.exit_code, done.output, done.error_output)
    print(process.run("sh", ["-c", "printf %s \"$1\"", "sh", "hi there"]).output)
    with process.Command("sh", ["-c", "echo first; exit 7"]) as command:
        print(command.wait(), command.output(), command.is_finished())
    process.set_variable("LUCE_STD_SURFACE", "value=with=equals")
    print(process.variable("LUCE_STD_SURFACE"), process.variable("LUCE_STD_NOT_SET"))
    var listed = false
    for entry in process.variables():
        listed = listed or entry == "LUCE_STD_SURFACE=value=with=equals"
    process.unset_variable("LUCE_STD_SURFACE")
    print(listed, process.variable("LUCE_STD_SURFACE"))
    let start = process.current_directory()
    process.change_directory("/")
    # a root: `/`, or the current drive's on Windows
    let root = process.current_directory()
    print(root.length > 0 and paths.root(root) == root)
    process.change_directory(start)
    print(process.current_directory() == start, process.id() > 0)
    return 0