nsIProcess.run()でスクリプトを実行していますが、出力を取得する唯一の方法は、出力をファイルに書き込んでから、javascript からファイルを読み取ることです。
しかし、何らかの理由で、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);
}
私のスクリプト.sh:
echo ok > /tmp/result.txt
my-script.sh からこの "ok" 出力を取得するためのより良い (そして機能する) 方法はありますか?
- アップデート
Xulrunner 1.9.2.15 を使用して Ubuntu 10.04 を使用しています