Today, when you execute a shell command with node. JS, you encounter a directory and file name with spaces.
According to common sense should escape, of course, you can write escape, but to deal with the complex escape, not so easy. So does the system provide it?
Google found that you can use
Child_process.execfile (file, [args], [options], [callback])
In the args array to help you escape.
On the code:
var execfile = require (' child_process '). ExecFile; var cmd = "Avconvert"; var args = ['-P ', ' presetapplem4a ', '-s ', oldname, '-O ', newname]; ExecFile (Cmd,args, function (Error, stdout, stderr) { console.log (' stdout: ' + stdout); Console.log (' stderr: ' + stderr); if (Error!== null) { console.log (' EXEC (' +cmd+ ') Error: ' + error); } });
In the code snippet above, Oldname and newname are probably file names that contain spaces and punctuation.
By passing it to the ARG array, the system will help you escape.
How to execute shell command inside node. js to escape string