简体   繁体   中英

child_process.fork is not working and idk the reason

I'm trying to use child_process.fork() but it's not working. I tried using spawn and that works. Can anyone help me?

 child_process.fork('node', ["bot.js"],{cwd:fs.readFileSync('./path.txt')+"\\Workroom\\"});

readFileSync is returning a buffer when you expect it to return a string. You need to set the encoding to 'utf8'. And I recommend using path.join instead of simply concatenating (assuming the content of path.txt is a valid path). your code would look something like this...

child_process.fork('node', ["bot.js"],
    {cwd: path.join(fs.readFileSync('./path.txt', 'utf8'),'Workroom')}
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM