简体   繁体   中英

Node.js copy UNIX executable file (Mac OS X)

So I have an executable UNIX file (which I extracted from a Mac App), and tried to duplicate it. The code is:

var dat = fs.readFileSync("~/FileZilla.app/Contents/MacOS/filezilla",{ flags:'r', encoding:"binary"});
fs.writeFileSync("~/filezilla_copy", dat,{ flags: 'w',  encoding: "binary",});

But what I end up getting is an un-readable document file and not a UNIX EXE file. I can't even run it through terminal, although supposedly I created an exact duplicate of the original file. How do I get this file to be recognized as a UNIX file?

You need to change the mode of the file to set the execute bit, use fs.chmodSync() . See here for details: How do I use chmod with Node.js

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