Skip to content
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

shell.exec(mv a/m.js b/) cannot return error stdout #1147

Closed
TulipLi opened this issue Jan 3, 2024 · 2 comments
Closed

shell.exec(mv a/m.js b/) cannot return error stdout #1147

TulipLi opened this issue Jan 3, 2024 · 2 comments
Labels
exec Issues specific to the shell.exec() API question Question from a user (which may not require code/documentation changes to the project)

Comments

@TulipLi
Copy link

TulipLi commented Jan 3, 2024

Node version (or tell us if you're using electron or some other framework):

16.14.0

ShellJS version (the most recent version/Github branch you see the bug on):

0.8.5

Operating system:

gitlab CI

Description of the bug:

when I run this command shell.exec('mv a/m.js b/)
and a/m.js is not exist, then will console no such file or directory,
but when I use

const res = shell.exec(`mv a/m.js b/`)
console.log('res:' + res)
// this return an empty string
// res:''

what I want is to get the error code or error message to do something.

Example ShellJS command to reproduce the error:

const res = shell.exec(`mv a/m.js b/`)
console.log('res:' + res)
// this return an empty string
// res:''

seems like delete { continue: true } can fix this issue
image

if (!fs.existsSync(src)) {
      common.error('no such file or directory: ' + src);
      return; // skip file
}
@nfischer
Copy link
Member

nfischer commented Jan 4, 2024

Did you try console.log('res:' + res.stderr)? The .stderr property is where the error message lives.

Check out https://github.com/shelljs/shelljs#shellstringstr

@nfischer nfischer added question Question from a user (which may not require code/documentation changes to the project) exec Issues specific to the shell.exec() API labels Feb 3, 2024
@nfischer
Copy link
Member

nfischer commented Feb 3, 2024

I'm going to assume the .stderr property solves this for you. Let me know if you're still seeing issues and we can look again.

@nfischer nfischer closed this as not planned Won't fix, can't repro, duplicate, stale Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exec Issues specific to the shell.exec() API question Question from a user (which may not require code/documentation changes to the project)
Projects
None yet
Development

No branches or pull requests

2 participants