Skip to content

Commit

Permalink
Merge pull request #7 from zeke/display-output-as-command-is-running
Browse files Browse the repository at this point in the history
display output as command is running
  • Loading branch information
zeke authored Jul 3, 2024
2 parents 181919d + 9d4a6cd commit 5e9e0a5
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { execSync } from 'node:child_process'
import { spawn } from 'node:child_process'
import minimist from 'minimist'
import { createClient } from './client.js'

Expand Down Expand Up @@ -61,11 +61,23 @@ for await (const part of completions) {
}
const shellCommand = output.join('')

try {
console.log(`Command: ${shellCommand}`)
console.log('')
const result = execSync(shellCommand).toString()
console.log(result)
} catch (error) {
console.log(`Command: ${shellCommand}`)
console.log('')

const child = spawn(shellCommand, { shell: true })

child.stdout.on('data', (data) => {
process.stdout.write(data)
})

child.stderr.on('data', (data) => {
process.stderr.write(data)
})

child.on('error', (error) => {
console.error(`Error executing command: ${error.message}`)
}
})

child.on('close', (code) => {
console.log(`Child process exited with code ${code}`)
})

0 comments on commit 5e9e0a5

Please sign in to comment.