2016-03-07 144 views
1

我想執行一個shell腳本來在dhtmlx實時更新的框架中啓動nodejs服務器。根據dhtmlx文檔,nodejs服務器將被放入web根目錄。我已經寫了位於/ var/WWW(其中的NodeJS文件夾位於)一個批處理文件,這樣服務器可以啓動,重新啓動或根據需要,而不必打開一個終端:執行Linux shell腳本時出錯

#!/bin/bash 
nodejs nodejs/server.js 

從腳本有是一個AJAX調用PHP腳本:

$("#starter").click(function(response){ 
    var jqxhr = $.ajax("./phpFunctions/nodeStarter.php") 
    .done(function(response) { 
     alert(response); 
    }) 
    .fail(function() { 
     alert(response); 
    }) 
}); 

在nodeStarter.php如下:

error_reporting(E_ERROR | E_WARNING | E_PARSE); 
$output = shell_exec("/var/www/nodeStart 2>&1; echo $?"); 
echo "<pre>$output</pre>"; 
unset $output; 

和錯誤消息: console error

咦?似乎是在web文件夾中尋找server.js,而不是我告訴它的web根目錄。我很困惑。

回答

2

嘗試

#!/bin/bash 
nodejs /var/www/nodejs/server.js 
+0

謝謝,這做到了。並且發現一個PHP錯誤一旦啓動, 未設置($ output); 不喜歡沒有看到任何括號。 – jazcam