How do we start another golang app?



  • There are two apps. How do you just start the file two?



  • You're gonna need a os/exec.

    Run starts the commandu and waits for her to end.

    Starts and doesn't wait until you call Wait.

    https://golang.org/pkg/os/exec/#Cmd.Run

    package main
    

    import (
    "bytes"
    "fmt"
    "log"
    "os/exec"
    "strings"
    )

    func main() {
    cmd := exec.Command("tr", "a-z", "A-Z")
    cmd.Stdin = strings.NewReader("some input")
    var out bytes.Buffer
    cmd.Stdout = &out
    err := cmd.Run()
    if err != nil {
    log.Fatal(err)
    }
    fmt.Printf("in all caps: %q\n", out.String())
    }


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2