Book Image

Hands-On Go Programming

By : Tarik Guney
Book Image

Hands-On Go Programming

By: Tarik Guney

Overview of this book

<p>With its C-like speed, simplicity, and power for a growing number of system-level programming domains, Go has become increasingly popular among programmers. Hands-On Go Programming teaches you the Go programming by solving commonly faced problems with the help of recipes. You will start by installing Go binaries and get familiar with the tools used for developing an application. Once you have understood these tasks, you will be able to manipulate strings and use them in built-in function constructs to create a complex value from two floating-point values. You will discover how to perform an arithmetic operation date and time, along with parsing them from string values. In addition to this, you will cover concurrency in Go, performing various web programming tasks, implementing system programming, reading and writing files, and honing many fundamental Go programming skills such as proper error handling and logging, among others. Whether you are an expert programmer or newbie, this book helps you understand how various answers are programmed in the Go language.</p>
Table of Contents (18 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributor
Preface
Index

Running child processes


In this video, we're going to see how to run child processes within your application. In our application, we will run a command called ls (in Linux) and dir (in Windows). The ls and dir command is an application that simply lists all the files within a given directory. Thus, from our current directory, it will give us hello.txt and main.go files. We are going to run this ls utility app within our application. So, the first thing we have to do is to use the exec package, which provides commands. We are going to use the ls command and not pass any argument right now. This will return the command itself. You will find two functions; one is start and the other one is run.

Note

The difference between start and r is, if you look at the documentation, you'll see that run starts the specified command and waits for it to complete. Based on your requirements, you can choose start or run.

We also have PID, which is the process ID, and we are going to output that to the console...