Calling External Processes and Handling Errors and Timeouts
Many command-line applications interact with other external commands or API services. This chapter will guide you through how to call these external processes and how to handle timeouts and other errors when they occur. The chapter will start with a deep dive into the os/exec
package, which contains everything you need to create commands that call external processes that give you multiple options for creating and running commands. You’ll learn how to retrieve data from the standard output and standard error pipes, as well as creating additional file descriptors for similar usage.
Another external process involves calling external API service endpoints. The net/http
package is discussed and is where we start defining the client, then create the requests that it executes. We will discuss the different ways requests can be both created and executed.
Timeouts and other errors can occur when calling either type of...