nodejs execSync中的printf给出错误 - 系统找不到指定的文件

时间:2017-10-15 01:42:28

标签: node.js

在节点中使用..

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

我收到错误..系统找不到指定的文件。

任何人都有任何想法如何解决这个问题?我需要使用printf。我想要做的就是打印<a>

我正在使用Windows GIT bash。节点v6.11.3

在命令行上.. printf '<a>'工作正常,但printf \'<a>\'会出现同样的错误。

1 个答案:

答案 0 :(得分:1)

尝试交换引号字符:

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

使用引号反过来说,执行shell(在Windows中为cmd.exe,我相信)似乎认为您要将名为“a”的文件重定向到printf(如printf < a)。