From 527559c656e380245d132972ce0bf661dd9bb393 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Fri, 24 May 2024 10:01:01 +0200 Subject: [PATCH] examples: cleanup `process/execve.v` (#21557) --- examples/process/execve.v | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/examples/process/execve.v b/examples/process/execve.v index f840c8dcd3..dbdeb5ac75 100644 --- a/examples/process/execve.v +++ b/examples/process/execve.v @@ -1,17 +1,14 @@ -module main - import os -fn exec(args []string) { - os.execve('/bin/bash', args, []) or { - // eprintln(err) - panic(err) - } -} - +// NOTE: `execve` executes a new child process, in place of the current process. +// Therefore, only the topmost example will be executed when it's not commented out. fn main() { - // exec(["-c","find /"]) //works - exec(['-c', 'find /tmp/']) // here it works as well + // Passes only an array of args. + 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'])! }