-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Go Recipes for Developers
By :
There are many use cases where you want to execute an external program to perform a task. Usually, this is because performing the same task within your own program is not possible or not easy. For example, you may choose to execute several instances of an external image processing program to modify a group of images. Another use case is when you want to configure some device using programs provided by its manufacturer. This recipe includes several ways to execute external programs.
Use exec.Command or exec.CommandContext to run another program from your program. exec.Command is appropriate if you do not need to cancel (kill) the child process or impose a timeout. Otherwise, use exec.CommandContext, and cancel or time out the context to kill the child process:
exec.Command (or exec.CommandContext) object using the name of the program and its arguments: