使用nodejs

时间:2016-01-13 14:12:26

标签: linux node.js child-process fs

我有一个非常有趣的问题。我在nodejs中生成一个子进程来创建一个受zip密码保护的文件。它应该模拟以下命令。

zip -P password -rf finalFileName.zip filePath

这是我写的代码

function(password, zipName) {

            let zip = spawn('zip', ['-P rolemodel','-rj', zipName, this.folderPath ]);

            return this;

    }

在解压缩最终的zip文件时,我收到无效的密码错误。

我在这里做错了什么?然而,我能够在终端上执行命令并使整个过程工作。

1 个答案:

答案 0 :(得分:1)

也许你可以尝试将每个参数放在引号中,如下所示:

zip = spawn('zip',['-P', 'password' , '-rj', 'archive.zip', 'complete path to archive file']);
zip .on('exit', function(code) {
...// Do something with zipfile archive.zip
...// which will be in same location as file/folder given
});