FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cli/src/exec.js at master · magic/cli · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
magic
/
cli
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
2
Code
Issues
2
Pull requests
1
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
cli
/
src
/
exec.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (31 loc) · 1.06 KB
Breadcrumbs
cli
/
src
/
exec.js
Copy path
File metadata and controls
39 lines (31 loc) · 1.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import
child_process
from
'child_process'
import
error
from
'@magic/error'
const
libName
=
'@magic/cli.exec'
/**
@typedef
{
child_process.ExecOptionsWithStringEncoding & { stderrToStdout?: boolean }
} CLIExecOptions */
/**
* Executes a shell command using child_process.exec
*
@param
{
string
} cmd - The shell command to execute.
*
@param
{
CLIExecOptions
} [options = {}] - Execution options.
*
@returns
{
Promise<string>
} Resolves with stdout or stderr (if stderrToStdout = true), rejects with Error.
*/
export
const
exec
=
(
cmd
,
options
)
=>
new
Promise
(
(
resolve
,
reject
)
=>
{
const
{
stderrToStdout
=
false
,
...
opts
}
=
options
||
{
}
child_process
.
exec
(
cmd
,
opts
,
(
err
,
stdout
,
stderr
)
=>
{
if
(
err
)
{
const
e
=
error
(
err
,
'E_EXEC_ERR'
)
reject
(
e
)
return
}
if
(
stderr
)
{
if
(
stderrToStdout
)
{
resolve
(
stderr
)
return
}
const
e
=
error
(
new
Error
(
`
${
libName
}
:
${
cmd
}
error:
${
stderr
}
`
)
,
'E_EXEC_STDERR'
)
reject
(
e
)
return
}
resolve
(
stdout
)
}
)
}
)
Back
|
FazBrowse Home
|
New Git URL