Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!