我正在運行一個腳本nsIProcess.run(),我發現獲得輸出的唯一方法是將輸出寫入文件,然後從JavaScript中讀取文件。在Xulrunner中獲取腳本輸出(shell腳本)的最佳方式是什麼?
但由於某些原因,當我從xulrunner應用程序執行它時,它不會生成帶有輸出的文件。這裏是我的功能:
function runProcess() {
// create an nsILocalFile for the executable
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces["nsILocalFile"]);
file.initWithPath("/home/me/my-script.sh");
write("FILE EXISTS = " + file.exists()); // it is printing TRUE, good!
// create an nsIProcess
var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(file);
// Run the process.
// If first param is true, calling thread will be blocked until
// called process terminates.
// Second and third params are used to pass command-line arguments
// to the process.
process.run(true, [], 0);
}
my-script.sh:
echo ok > /tmp/result.txt
有沒有更好的(和工作)的方式來得到my-script.sh這個 「OK」 輸出?
--update
我在Ubuntu 10.04使用的XULrunner 1.9.2.15
嘗試在您的shell腳本中使用絕對路徑。它的當前目錄可能不是你想象的那樣。 – 2011-03-04 16:40:02
那麼腳本是否被執行,但是文件沒有被寫入,或者腳本沒有被執行?可以確認它確實以某種方式運行? – pc1oad1etter 2011-03-04 17:57:29
@丹尼斯威廉姆森好點。不幸的是,它仍然沒有創建文件。 – 2011-03-04 18:01:03