-
-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get Error: Command failed with exit code 2:
while also getting back the expected stdout
#515
Comments
Hi @ctf0, What happens if you replace the import { execFile } from 'node:child_process'
import { promisify } from 'node:util'
const pExecFile = promisify(execFile);
const filesNamesRg = 'Kernel|Handler'
const rgExcludeDirs = 'vendor,stubs'
const { stdout } = await pExecFile('rg', [
`'((\\\\*\\w+\\\\+)+(${filesNamesRg}))'`,
'--mmap',
'--follow',
'--no-messages',
'--smart-case',
'--only-matching',
"--glob='!*blade.php'",
`--glob='!{${rgExcludeDirs}}'`,
"--glob='**/*.php'",
"./", // https://github.com/BurntSushi/ripgrep/issues/2056#issuecomment-966306579
], {
cwd : '/some/path',
shell : true, // without shell no results are returned, only error
});
console.log(stdout); |
Error: Command failed: rg '((\\*\w+\\+)+(...
at ChildProcess.exithandler (node:child_process:408:12)
at ChildProcess.emit (node:events:526:28)
at maybeClose (node:internal/child_process:1092:16)
at Socket.<anonymous> (node:internal/child_process:451:11)
at Socket.emit (node:events:526:28)
at Pipe.<anonymous> (node:net:687:12)
at Pipe.callbackTrampoline (node:internal/async_hooks:130:17 same error with/without |
Is this the same error as when using Execa? |
no, different |
@ctf0 Could you please elaborate and give additional details so we can better help you? In particular, the error message looks the same to me (or more precisely have non-significant small differences) whether Execa is used or not. I am unable to reproduce your setup since it seems to rely on specific files being present locally when the command is executed. More importantly, I am not clear about whether your problem is that:
|
np, the steps are
not exactly, because with execa i have this error + output, without execa i have a different error, true that both doesnt give much of meaning to debug but thier differences prove something.
great, how can we only get the output without the error ?, if we can view them then thier must be a way to extract them
but cant we understand the exact reason why with the options it works & without it it doesnt, at least in the main example with execa. if there is a way i can debug this on my part, plz tell me how. aside from that, does the size of the arg change the behavior ? for example lets say the |
Thanks for the information @ctf0. I am sorry but, based on this, I am afraid those questions do not seem to be specifically related to Execa, but with child process execution in general. Sorry again for not being able to help you for this matter @ctf0. |
i focken found iiiiiiiiiiiiiit. first check https://github.com/nodejs/node-v0.x-archive/blob/master/doc/api/process.markdown#exit-codes for codes description "i think this should be part of the reject error instead of just a number" anyway error code 2 is
so as the error says, it seems that the command have something that shell/bash thinks is a builtin option & after doing some reading it seems that so the final usage should be const filesNamesRg = 'Kernel|Handler'
const rgExcludeDirs = 'vendor,stubs'
const { stdout } = await execa('rg', [
`'((\\\\*\\w+\\\\+)+(${filesNamesRg}))'`,
'--mmap',
'--no-messages',
'--smart-case',
'--only-matching',
"--glob='!*blade.php'",
`--glob='!{${rgExcludeDirs}}'`,
"--glob='**/*.php'",
"./", // removing this wont resolve anything
], {
cwd : '/some/path',
shell : true, // removing this will give error code 1 instead
});
console.log(stdout); |
Thanks @ctf0 for confirming the problem was with |
not exactly, because if we ran the command in a trmnl it will work, also the argument comes after the command in the spawn items order, |
am trying to use execa with ripgrep, however for some reason am getting both the error & data as an error
-error
any help how to fix this is appreciated.
The text was updated successfully, but these errors were encountered: