exec (async)
exec (async)
Node.js
const { exec } = require('child_process')
exec(`echo 'hello world'`, (error, stdout, stderr) => {
if (error) {
console.error(err)
}
if (stderr) {
console.error(stderr)
}
if (stdout) {
console.log(stdout)
}
})
Output
hello world
Go
package main
import (
"os"
"os/exec"
)
func main() {
cmd := exec.Command("echo", "hello world")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
}
Output
hello world
