Executing a script inside an ASAR archive
Asked Answered
M

1

2

I am attempting to run a script that is archived inside an ASAR file like so:

var spawn  = require('child_process').spawn;

var t = spawn('node', ['./bundle.asar/main.js'], {});

t.on('data', function(data){      
  console.log(data.toString());
});

t.stdout.pipe(process.stdout);
t.stderr.pipe(process.stderr);

FYI the above script is situated outside the ASAR archive. However, all I get is the following error:

Cannot find module 'C:\Users\MyUser\tests\asar-test\bundle.asar\main.js'

The official docs on this particular issue are nonexistent. Is there some way to either read the ASAR file or require a script inside it? Thank you.

Medawar answered 11/12, 2016 at 10:26 Comment(0)
M
2

For posterity, the answer to this is to require your .js file like so:

var spawn  = require('child_process').spawn;
var myScript = require('./bundle.asar/main.js');

var t = spawn('node', [myScript], {});

t.on('data', function(data){      
  console.log(data.toString());
});

t.stdout.pipe(process.stdout);
t.stderr.pipe(process.stderr);

Hope this helps.

Medawar answered 29/1, 2017 at 8:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.