Passing arguments to a process
The mechanics of passing arguments to a child process can be confusing. Shell environments parse and expand process arguments. For example, a *.txt
argument is replaced by a list of filenames matching that pattern, and each of those filenames becomes a separate argument. This recipe talks about how to pass such arguments to child processes correctly.
There are two options to pass arguments to a child process.
Expanding arguments
The first option is to perform the shell argument processing manually.
How to do it...
To manually perform shell processing, follow these steps:
- Remove shell-specific quoting from arguments, such as the shell command:
- The
./prog "test
directory"
shell command becomescmd:=exec.Command("./prog","test directory")
. - The
./prog dir1 "long dir name" '"quoted name"'
Bash command becomescmd:=exec.Command("./prog", "long dir name", "...
- The