toolkit
toolkit copied to clipboard
The `exec` action hangs when last argument is enclosed in double quotes
Describe the bug
As part of a custom action I'm writing, I'm trying to use the exec action to run ripgrep in the following way:
rg --type rust --files-without-match --fixed-strings "Copyright (C) 2022 MaidSafe."
I'm attempting to do this using the exec action:
async function runRipGrep(searchString) {
let output = '';
const options = {};
options.listeners = {
stdout: (data) => {
output += data.toString();
}
};
await exec.exec(
'rg',
[
'--type', 'rust', '--files-without-match',
'--fixed-strings', `"${searchString}"`
],
options);
return output;
}
When exec runs as above, it hangs indefinitely until the workflow run is cancelled.
To Reproduce
Invoke rg using the mechanism above.
Expected behavior The process should run and return its output.
Additional context
I tried different ways of running it. Curiously, if you add an additional argument after the double quotes enclosed argument, exec does return:
async function runRipGrep(searchString) {
let output = '';
const options = {};
options.listeners = {
stdout: (data) => {
output += data.toString();
}
};
await exec.exec(
'rg',
[
'--type', 'rust', '--files-without-match',
'--fixed-strings', `"${searchString}"`, '.'
],
options);
return output;
}
However, the process doesn't produce the same output as per executing it from the shell, which may suggest the double quotes are causing some sort of parsing issue. It's almost like the search string is not supplied.
The problem here appears to be that the process needs to be launched in a particular way, which is documented here.
I worked around by using the native process library:
const { spawnSync } = require('child_process');
async function runRipGrep(searchString) {
let output = '';
const options = {};
options.shell = true;
options.stdio = ['ignore', 'pipe', 'inherit'];
const child = spawnSync(
'rg',
[
'--type', 'rust', '--files-without-match',
'--fixed-strings', `"${searchString}"`
],
options);
output = child.stdout.toString();
return output;
}
The exec package doesn't expose options for setting shell (not sure if that's a security issue?) or stdio, both of which seem to be necessary here.
I ran into same problem with this command.
exec("gator", [
"test",
"--filename=gatekeeper/policies/",
]);
It invokes the command, but hangs forever.