Closed KingKarrow closed 4 years ago
Hello again! I was able to solve this. It turns out, the issue is pretty universal across different packaging modules: once packaged inside the exe, you can only reference internal files with the fs
commands! So basically, you're only going to get scripts read in as big strings. My next issue was figuring out how to call them. It took a while to get one thing to work consistently, but here's what I ended up with:
...
var startStr = fs.readFileSync(path.join(__dirname, 'start.ps1')).toString();
ps.addCommand('& {' + startStr + '} \n');
...
Note: The \n
is very important, because without it the command fails to fire and it just hangs.
Also, here is an example with an argument (because addArgument would not work here):
...
var arg1 = 14;
var startStr = fs.readFileSync(path.join(__dirname, 'start.ps1')).toString();
ps.addCommand('& {' + startStr + '} ' + arg1 + '\n');
...
So that's it! I have .ps1 files successfully hidden away inside my exe, and still being executed.
Hello, I found an issue that I haven't been able to get around. I want to use npm pkg (https://www.npmjs.com/package/pkg) to bundle my code into an easy executable and keep clients from seeing the source. Unfortunately, though I've enjoyed working with this module to launch my Powershell scripts, I don't think it works as well inside a pkg'd project.
Here is a simple "ps.js", which uses node-powershell to run my Powershell script:
.... and "start.ps1":
Running
node ps.js
from a Powershell window works fine, returning the following output:I then run the
pkg
command:pkg ps.js --output ps.exe
, and runps.exe
; The exe version will break. Here is the output:So... am I doing something wrong? Is there a different way to run/reference scripts? Because I only saw the possibility of using
addCommand
. Or, is it just not possible to call a script while inside pkg?