带有正则表达式返回的运行子进程无法识别错误

问题描述 投票:0回答:1

我使用以下代码来获取目标文件

const command = `make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\\/t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'`;


    cp.exec(command, options, (error, stdout, stderr) => {
          if (error) {
            reject({ error, stdout, stderr });
          }

当通过代码使用它时出现错误(Windows)

"'$)' is not recognized as an internal or external command,
operable program or batch file.
"

但是,如果我在终端可以运行]上运行确切的命令,则!!!!可能是什么问题呢?

顺便说一句,在Mac上,代码正在工作,是否有任何解决方法,正则表达式会丢失什么?

我也尝试过使用https://github.com/shelljs/shelljs并得到完全相同的错误,也许我错过了一些转义符?

我用这个

https://nodejs.org/api/child_process.html#child_process_class_childprocess

我使用以下代码来获取make文件目标const command =`make -qp | awk -F':''/ ^ [a-zA-Z0-9] [^ $#\\ / t =] *:([^ =] | $)/ {split($ 1,A,/ /); for(i in A)print A [i]}'`; cp.exec(命令,选项,(...

javascript node.js regex makefile gnu-make
1个回答
0
投票

不能完全回答您的问题,但是我建议您使用https://github.com/shelljs/shelljs来避免浪费时间在不同平台上的命令之间。

© www.soinside.com 2019 - 2024. All rights reserved.