2017-09-13 7 views
0

自分のノードでサービスapache2のステータスを実行するときに、私は非常に奇妙な動作に気付きました。これはコードです:Apacheが動作しているとき、私は、このコマンドを実行するとサービスが停止しているサービス状況を確認する方法

app.post('/getStatus', jsonParser, function(req,res){ 

    exec("service apache2 status", function(err, stdout){ 
    if(err) throw err; 
    var statuspmtatmp = /Active: [a-z]* [\(][a-z]*[\)]/g.exec(stdout.toString())[0]; 

    res.json(statuspmtatmp); 
    }); 

}); 

すべてがOKですが、私は、Apacheを停止し、彼らは私が状態を確認しようと、私はエラーを取得する場合:

間違っている何
Error: Command failed: /bin/sh -c service apache2 status 
at ChildProcess.exithandler (child_process.js:213:12) 
at emitTwo (events.js:87:13) 
at ChildProcess.emit (events.js:172:7) 
at maybeClose (internal/child_process.js:821:16) 
at Socket.<anonymous> (internal/child_process.js:319:11) 
at emitOne (events.js:77:13) 
at Socket.emit (events.js:169:7) 
at Pipe._onclose (net.js:469:12) 

?なぜ、Apacheが動いているのですか?だから、実行停止とは、あなたがnode docsで読むことができたよう

if(err){ 
    //code to handle the error 
} 

を行い、エラー

を投げる

if(err) throw err; 

:あなたはエラーをチェックして、この行にエラーを投げている

答えて

0

If a callback function is provided, it is called with the arguments (error, stdout, stderr). On success, error will be null. On error, error will be an instance of Error. The error.code property will be the exit code of the child process while error.signal will be set to the signal that terminated the process. Any exit code other than 0 is considered to be an error.

+0

なぜこの行に?なぜ私が見ているコードを渡していないのですか?私はサービスが疲れているという情報を持っていますか? – cyprian

+0

私の答えは – aaron0207

+0

Worked? – aaron0207

関連する問題