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...