Accessing child properties

Once the command has started its execution, synchronously or not, the underlying os.Process gets populated and it is possible to see its PID, as we can see in the following example:

package main

import (
"fmt"
"os/exec"
)

func main() {
cmd := exec.Command("ls", "-l")
if err := cmd.Start(); err != nil {
fmt.Println(err)
return
}
fmt.Println("Cmd: ", cmd.Args[0])
fmt.Println("Args:", cmd.Args[1:])
fmt.Println("PID: ", cmd.Process.Pid)
cmd.Wait()
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.214.155