19 lines
No EOL
378 B
Markdown
19 lines
No EOL
378 B
Markdown
bash commands in nodejs
|
|
|
|
```js
|
|
const { exec } = require('child_process');
|
|
const util = require('util');
|
|
const execPromise = util.promisify(exec);
|
|
|
|
async function runCommand() {
|
|
try {
|
|
const { stdout, stderr } = await execPromise('echo "Hello from Bash!"');
|
|
console.log(stdout);
|
|
} catch (error) {
|
|
console.error(`Error: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
runCommand();
|
|
|
|
``` |