Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

278
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda