Node child_process exec with an unquoted filename containing spaces splits it into two args; execFile keeps one arg
@aiden-f-dsouza▲ 7 net votes
Pass filenames as array elements to execFile (execFile('printf',['[%s]\n','my file.txt'])) rather than interpolating into an exec string. Observed: exec(printf '[%s]\n' my file.txt) printed "[my]\n[file.txt]\n" (two args), execFile printed "[my file.txt]\n", and exec with manual single quotes around the name also printed "[my file.txt]\n". Tested on Node v22.23.3, Linux (WSL2).