#spawn or readline replacement

1 messages · Page 1 of 1 (latest)

dry dune
#

Currently looking for a suitable replacement of child_process/spawn and readline (node:readline/promises) - I found bun-utilities/spawn but no examples of how to use it. The code I'm trying to replicate is:

const { spawn } = require('child_process')
const readline = require('node:readline/promises')

const child = spawn('tail -f', ['access.log'])

rl = readline.createInterface({
  input: child.stdout,
  output: null,
})

for await (const line of rl) {
  this.processLine(line)
}

How can I do this in Bun?

I saw the Github issues and saw that readline isn't implemented yet, but was suggested to use exec instead (because it provides a string out). Unfortunately the example didn't say whether exec would work for some long running process like tail -f access.log

polar oriole
#

temp solution is use prompt global function if you need to prompt user

dry dune
#

@polar oriole just a polite ping to make sure you're aware.

polar oriole
#

Try to add .js after bun-utilities/spawn

dry dune
#

@polar oriole Same result

polar oriole
#

its issue with bun v0.1.11

#

i think

#

@cloud crypt

#
GitHub

Benchmarks between languages & js runtimes. Contribute to xHyroM/benchmarks development by creating an account on GitHub.

GitHub

Benchmarks between languages & js runtimes. Contribute to xHyroM/benchmarks development by creating an account on GitHub.

#

ill create gh issue

wide owlBOT
polar oriole
#

not sure if its exports issue

cloud crypt
#

hm

cloud crypt
#

@polar oriole could you write some tests in src/bun.js/test that check that the variations of import and require work as expected? there are some tests for this, but they're more like unit tests than integration tests OR they're for bun dev which behaves slightly differently in some cases with require

this particular issue, I think, is caused by module.exports = being a function

polar oriole
#

sure i can

dry dune
#

Appears latest bun fixed the exports issue. Not sure how, could have been from v0.1.12

dry dune
polar oriole
#

👍

#

Today I'll implement env variables

#

And try to look for simple stdout event

cloud crypt
#

@polar oriole i plan to implement child_process probably next week

#

as a heads up

#

maybe Bun.spawn

#

first and then child_process

polar oriole
#

Okay

#

👍👍👍

#

So probably better way is to wait for your implementation 👍

#

Thanks for informations

dry dune
#

@cloud crypt just know, that I was trying my best to avoid pinging you. I don't want you to think I'm a leech. I KNOW you're very busy and working on ALL kinds of bug fixes, perf improvements, and features for Bun. I understand Bun isn't ready for some production use-cases. I'm aware that child_process is on the agenda; I was trying to hack a way around it until it became available.

cloud crypt
#

child_process is necessary for Vite