要用nodejs執行cmd,需要引入一個包node-cmd
npm install node-cmd
var cmd=require('node-cmd'); cmd.get( 'notepad',//畫圖板 function(data){ console.log("data") } ); cmd.get( 'C:\\Windows\\System32\\Calc.exe', //計算器 function(data){ console.log("cacul") } ); cmd.run('touch example.created.file'); // notepad--------打開記事本 //'mspaint' 畫圖板