简体   繁体   English

Node.js复制UNIX可执行文件(Mac OS X)

[英]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. 因此,我有一个可执行的UNIX文件(我从Mac App中提取了该文件),并尝试将其复制。 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. 但是我最终得到的是一个无法读取的文档文件,而不是UNIX EXE文件。 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? 如何使该文件被识别为UNIX文件?

You need to change the mode of the file to set the execute bit, use fs.chmodSync() . 您需要更改文件的模式以设置执行位,请使用fs.chmodSync() See here for details: How do I use chmod with Node.js 有关详细信息,请参见此处: 如何将chmod与Node.js结合使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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