exec (sync)


Node.js

  1. const { execSync } = require('child_process')
  2. const output = execSync(`echo 'hello world'`)
  3. console.log(output.toString())

Output

  1. hello world

Go

  1. package main
  2. import (
  3. "fmt"
  4. "os/exec"
  5. )
  6. func main() {
  7. output, err := exec.Command("echo", "hello world").Output()
  8. if err != nil {
  9. panic(err)
  10. }
  11. fmt.Println(string(output))
  12. }

Output

  1. hello world