最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Run file after file download complete - Stack Overflow

programmeradmin1浏览0评论

I am very new to node-webkit. I am using the following code to download a file. How would I go about running the file automatically when the file has finished?

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);
});

I am very new to node-webkit. I am using the following code to download a file. How would I go about running the file automatically when the file has finished?

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);
});
Share Improve this question edited Oct 10, 2013 at 4:45 hexacyanide 91.9k31 gold badges166 silver badges162 bronze badges asked Oct 10, 2013 at 1:38 user2387226user2387226
Add a ment  | 

1 Answer 1

Reset to default 6

Just use the writable stream's close event and spawn a child process. The event will fire once the response has pleted piping to the stream.

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
  });
});
发布评论

评论列表(0)

  1. 暂无评论