Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

277
Visualizações
Nodejs child_process spawn option arguments with dashes("--")

I'm trying to run a child_process spawn with arguments that includes "--", but it doesn't seems to register that for a reason.

The command I'm trying to spawn is: wp-env run tests-cli "wp plugin update --all"

(This is a cli package to run a wordpress environment - https://www.npmjs.com/package/@wordpress/env)

The double quotations here are important for the command to work properly, so I think it might be part of the problem.

Here is the general idea of the code I'm trying to use:

const { spawn } = require("child_process");
 
const child = spawn('npx', [
    "wp-env",
    "run",
    "tests-cli",
    "wp",
    "plugin",
    "update",
    "--all"
], {shell: true});
 
var scriptOutput = "";
 
child.stdout.setEncoding('utf8');
 
child.stdout.on('data', function(data) {
    console.log('stdout: ' + data);
    data=data.toString();
    scriptOutput+=data;
});
 
child.stderr.setEncoding('utf8');
child.stderr.on('data', function(data) {
    console.log('stderr: ' + data);
    data=data.toString();
    scriptOutput+=data;
});
 
child.on('close', function(code) {
    console.log('closing code: ' + code);
    console.log('Full output of script: ',scriptOutput);
});

This is the output I'm getting:

Starting 'wp plugin update' on the tests-cli container. 

I tried lots of other similar combination, but none of them worked for my sadly.

Couldn't find any clues for the on google, so hopefully someone here would be able to assist with that. I assume the root cause is not actually related specifically to this package, but I didn't actually encounter an issue with using "--" as arguments in general, so I think it's related to this combination along with the requirement for the double quotations.

For example:

const child = spawn('npx', [
    "--version"
], {shell: true});

This would work just fine.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

What you are doing is actually running:

wp-env run tests-cli wp plugin update --all

Note: without the quotes.

If you want wp-env run tests-cli "wp plugin update --all" then you need to do:

const child = spawn('npx', [
    "wp-env",
    "run",
    "tests-cli",
    "wp plugin update --all"
], {shell: true});

That's what quotes do in bash: it treats everything inside it as a single argument.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda