Execute and get the output of a shell command in node.js

前端 未结 5 578
无人及你
无人及你 2020-11-27 10:56

In a node.js, I\'d like to find a way to obtain the output of a Unix terminal command. Is there any way to do this?

function getCommandOutput(commandString){         


        
5条回答
  •  余生分开走
    2020-11-27 11:33

    Thanks to Renato answer, I have created a really basic example:

    const exec = require('child_process').exec
    
    exec('git config --global user.name', (err, stdout, stderr) => console.log(stdout))
    

    It will just print your global git username :)

提交回复
热议问题