Enrique Moreno Tent
Enrique Moreno Tent

Reputation: 25267

Node.js: escaping spaces when executing a unix command

Im using this command to compress files in node.js:

var command = '7z a ' + dest + ' ' + orig;
exec( command, function(err, stdout, stderr) { ...});

The problem comes when a file has spaces like 7z a my vacation.zip my vacation.pdf

How could I escape dest and orig?

Upvotes: 2

Views: 1209

Answers (1)

neo
neo

Reputation: 801

Try to use spawn:

var spawn = require('child_process').spawn,
    ls    = spawn('ls', ['-l', '/tmp/test with spaces']);

    ls.stdout.on('data', function (data) {
        console.log('stdout: ' + data);
    });

Upvotes: 3

Related Questions