我是node-webkit的新手。我使用以下代码下载文件。文件完成后如何自动运行文件?
var https = require('https');
var fs = require('fs');
var file = fs.createWriteStream("update_setup.exe");
var request = https.get(url + "/appdata/update_setup.exe", function (response) {
response.pipe(file);
});
答案 0 :(得分:3)
只需使用可写流的close
事件并生成子进程。响应完成对流的管道后,事件将触发。
var https = require('https');
var fs = require('fs');
var exec = require('child_process').exec;
var file = fs.createWriteStream('update_setup.exe');
var request = https.get(path, function(res) {
res.pipe(file);
});
file.on('close', function() {
exec('update_setup.exe', function(err, stdout, stderr) {
// output from starting
});
});