简体   繁体   中英

printf in nodejs execSync gives error - the system cannot find the file specified

In node when using ..

var child_process = require('child_process')
child_process.execSync("printf 'a'") // works fine
child_process.execSync("printf '<a>'") // throws the system cannot find the file specified

I get the error .. the system cannot find the file specified.

Anyone got any ideas how to fix this? I need to use printf. All I want to do is print <a>

I am using Windows GIT bash. Node v6.11.3

On the command line .. printf '<a>' works fine but printf \\'<a>\\' gives the same error.

Try swapping quote characters:

child_process.execSync('printf "<a>"')

With the quotes the other way around, the executing shell (which is cmd.exe in Windows, I believe) seems to think that you want to redirect a file called "a" into printf (like printf < a ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM