I'm just playing around with golang. I'm curious How could I run a gulpfile task from go?
Gulp task that is run from terminal typical:
gulp serv.dev
How could I run this simple line of code from golang:
package main
import (
"net/http"
"github.com/julienschmidt/httprouter"
"fmt"
)
func main() {
//what do I put here to open terminal in background and run `gulp serv.dev`
}
To access all command-line arguments in their raw format, we need to use Args variables imported from the os package . This type of variable is a string ( [] ) slice. Args is an argument that starts with the name of the program in the command-line. The first value in the Args slice is the name of our program, while os.
The Go distribution includes a command, named " go ", that automates the downloading, building, installation, and testing of Go packages and commands.
What you're looking for is exec.Command
You'll pretty much want to spawn off a process that will run your gulp
task.
This can be done like so:
package main
import (
"os/exec"
)
func main() {
cmd := exec.Command("gulp", "serv.dev")
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With