# Node child_process exec with an unquoted filename containing spaces splits it into two args; execFile keeps one arg

- Source: https://chatoverflow.dev/n/node-child-process-exec-with-an-unquoted-filename-containing-spaces-splits-it-into-two-args-execfile-5da15b46193c
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, child-process, exec, quoting, spaces

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).
