vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.33k stars 1.02k forks source link

pkg can't use execFile correctly #2024

Closed introspection3 closed 11 months ago

introspection3 commented 1 year ago

What version of pkg are you using?

5.8.1

What version of Node.js are you using?

18.5

What operating system are you using?

windows ,maybe linux too

What CPU architecture are you using?

x64

What Node versions, OSs and CPU architectures are you building for?

node18-win32-x64

Describe the Bug

file1:s.js---->s.exe console.log(process.argv);

const { spawn,execFile } = require('child_process'); setInterval(() => { console.log(process.argv); }, 10000);

setTimeout(() => { console.log('s.exe','start er.exe'); let argv0=process.argv[0]; let rootPath=require('path').dirname(argv0);

let exePath=require('path').join(rootPath,'er.exe');
console.log('s.exe','exePath='+exePath);
startAsync(exePath,rootPath);

}, 5000);

var exec = require('child_process').exec; function startAsync(cmd){

execFile(cmd, function(error, stdout, stderr) {
    if(error){
        console.error(error);
    }
    else{
        console.log("success");
    }
});

}

// pkg -t node18-win32-x64 s.js

file2: er.js---->er.exe

console.log(process.argv); const exec = require('child_process').exec; const { spawn,execFile } = require('child_process'); setInterval(() => { console.log('i am er.exe'); }, 10000); function startAsync(cmd){

execFile(cmd, function(error, stdout, stderr) {
    if(error){
        console.error(error);
    }
    else{
        console.log("success");
    }
});

}

setTimeout(() => { console.log('er.exe','start s.exe'); let argv0=process.argv[0]; let rootPath=require('path').dirname(argv0);

let exePath=require('path').join(rootPath,'er.exe');
console.log('er.exe','exePath='+exePath);
startAsync(exePath,rootPath);

}, 5000);

// pkg -t node18-win32-x64 er.js

bug description

s.exe can't call er.exe

Expected Behavior

can call exe

To Reproduce

as above

introspection3 commented 1 year ago

code.zip souce code