C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Start: We call the Start func, and a Firefox window pops upon the computer. Start() does not wait for the process to end.
Golang program that uses Command, Start
package main
import (
"fmt"
"os/exec"
)
func main() {
// Create command.
// ... The application is not executed yet.
cmd := exec.Command("/home/sam/Downloads/firefox/firefox-bin")
fmt.Println("Starting command")
// Run firefox-bin.
// ... This starts a web browser instance.
// It does not wait for it to finish.
cmd.Start()
fmt.Println("DONE")
}
Output
Starting command
DONE
Here: We open Firefox and view Wikipedia's English home page. The next several hours of your time might disappear quickly.
Golang program that uses Command with argument
package main
import (
"fmt"
"os/exec"
)
func main() {
// New command with 1 argument.
browser := "/home/sam/Downloads/firefox/firefox-bin"
argument := "https://en.wikipedia.org/";
cmd := exec.Command(browser, argument)
// Run firefox-bin and load URL specified in argument.
cmd.Start()
fmt.Println("DONE")
}
Output
DONE
Golang program that uses Command with Run
package main
import (
"fmt"
"os/exec"
)
func main() {
// Run this Python program from Go.
cmd := exec.Command("python", "/home/sam/test.py")
fmt.Println("Running")
// Wait for the Python program to exit.
err := cmd.Run()
fmt.Println("Finished:", err)
}
Output
Running
Finished: exit status 100
Python program:
# This is a Python program.
exit(100)