Chapter 6 Controlling Processes

Powerful Command-Line Applications in Go — by Ricardo Gerardi (59 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Wrapping Up | TOC | Executing External Programs 👉

So far, you’ve developed several command-line tools with Go by executing tasks with your own algorithms. In some situations, it’s easier to delegate some of these tasks to more specialized programs that are already available on your system. For example, you may want to use git to execute version control commands against a Git repository or launch Firefox to display a web page on a browser, as you did in Adding an Auto-Preview Feature, when you built the Markdown Preview tool.

In some cases, these specialized programs have an API available that you can call directly from your program. When this isn’t available, you have to use their functionality by executing external commands from your Go program.

Go provides some lower-level libraries, such as syscall, but, unless you have specific requirements, it’s best to use the higher-level interface provided by the os/exec package.

In this chapter, you’ll apply the os/exec package to develop a simple, but useful, implementation of a Continuous Integration (CI) tool for your Go programs. A typical CI pipeline consists of several automated steps that continuously ensure a code base or an application is ready to be merged with some other developer’s code, usually in a shared version control repository.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.