Introduction
In some cases, Go programs need to spawn non-Go processes. This challenge aims to demonstrate how to spawn external processes in Go.
This tutorial is from open-source community. Access the source code
In some cases, Go programs need to spawn non-Go processes. This challenge aims to demonstrate how to spawn external processes in Go.
The challenge requires the implementation of a Go program that spawns external processes and collects their output.
## The spawned programs return output that is the same
## as if we had run them directly from the command-line.
$ go run spawning-processes.go
> date
Thu 05 May 2022 10:10:12 PM PDT
## date doesn't have a `-x` flag so it will exit with
## an error message and non-zero return code.
command exited with rc = 1
hello > grep
hello grep
-a > ls -l -h
drwxr-xr-x 4 mark 136B Oct 3 16:29 .
drwxr-xr-x 91 mark 3.0K Oct 3 12:50 ..
-rw-r--r-- 1 mark 1.3K Oct 3 16:28 spawning-processes.go
This challenge demonstrated how to spawn external processes in Go using the exec
package. The program was able to spawn external processes that take no arguments or input, take arguments and print something to stdout, take input from stdin and print something to stdout, and take a full command with a string. The program also handled errors that may arise during the execution of the external processes.