The command string to execute in the terminal or command prompt. Can be any valid shell command including pipes, redirects, and command chaining.
OptionalEcho: false | ((Return: any, _Error?: boolean) => Promise<void>)Optional parameter controlling output handling:
false: Suppresses all stdout/stderr outputundefined: Default console logging of stdout/stderrPromise
// Execute command with default logging
await exec('ls -la');
// Execute command with custom output handling
await exec('git status', (output, isError) => {
if (isError) console.error('Error:', output);
else console.log('Output:', output);
});
// Execute command silently
await exec('npm install', false);
Asynchronously executes a command and handles stdout/stderr output. This function spawns a child process to execute the given command and provides flexible output handling through the Echo parameter.