exec (sync)
exec (sync)
Node.js
const { execSync } = require('child_process')
const output = execSync(`echo 'hello world'`)
console.log(output.toString())
Output
hello world
Go
package main
import (
"fmt"
"os/exec"
)
func main() {
output, err := exec.Command("echo", "hello world").Output()
if err != nil {
panic(err)
}
fmt.Println(string(output))
}
Output
hello world
