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.