examples: cleanup process/execve.v (#21557)

This commit is contained in:
Turiiya 2024-05-24 10:01:01 +02:00 committed by GitHub
parent ccfa65aa14
commit 527559c656
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,17 +1,14 @@
module main
import os import os
fn exec(args []string) { // NOTE: `execve` executes a new child process, in place of the current process.
os.execve('/bin/bash', args, []) or { // Therefore, only the topmost example will be executed when it's not commented out.
// eprintln(err)
panic(err)
}
}
fn main() { fn main() {
// exec(["-c","find /"]) //works // Passes only an array of args.
exec(['-c', 'find /tmp/']) // here it works as well os.execve(os.find_abs_path_of_executable('ls')!, ['-lh', '-s'], [])!
// exec(["-c","find","/tmp/"]) // does not work I guess is normal // Considers args that would need to be passed within quotes. E.g.: `bash -c "ls -lh"`.
os.execve(os.find_abs_path_of_executable('bash')!, ['-c', 'ls -lah -s'], [])!
// Passes an environment variable that affects the commands output.
os.execve(os.find_abs_path_of_executable('man')!, ['true'], ['MANWIDTH=60'])!
} }