0

I want to use the following string and put it into childprocess


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

I was able to run it on the terminal succesfully however when I put it for child process I got error:

I try like this

let commandLine = "make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}' | sort -u";
    try {
        let { stdout, stderr } = await exec(commandLine, { cwd: workspaceRoot });

any idea ?

error :

awk: nonterminated character class ^[a-zA-Z0-9][^$#
 source line number 1
 context is
     >>> /^[a-zA-Z0-9][^$#/ <<< 

this is the idea... How do you get the list of targets in a makefile?

Beno Odr
  • 1,123
  • 1
  • 13
  • 27

1 Answers1

1

Backslash is terminated at JS string, so instead of \/ is only / passing through.

Use:

  • Double backslash \\\/ in string.
  • Wrap string into raw backticks.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

m1k1o
  • 2,344
  • 16
  • 27