You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to implement a websocket server which executes shell commands and streams the output over a WebSocket. I've got it working using node:child_process but I can't seem to find a way to send lines back over the web socket using Bun.spawn.
but I can't figure out an equivalent for Bun.spawn. I've tried looping over the piped stderr but it just send it through as one big string instead of line by line as they come in.
constcmd=Bun.spawn(["some-command","arg1","arg2"],{onExit: ()=>{ws.close(10003,'program exited');},stderr: "pipe",});forawait(constlineofcmd.stderr){// "line" here isn't actually a line, it's the entire stderr.ws.send(JSON.stringify({type: "output",source: "stdout",data: newTextDecoder().decode(line),}asOutputMessage),);}
In the Bun case, cmd.stdout.on doesn't exist and I can't find any way to replicate the node behaviour.
Is this just something that is expected and I should be using the node library or should I be able to achieve the same behaviour via Bun?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
I'm trying to implement a websocket server which executes shell commands and streams the output over a WebSocket. I've got it working using
node:child_process
but I can't seem to find a way to send lines back over the web socket usingBun.spawn
.With
node:child_process
, I can dobut I can't figure out an equivalent for
Bun.spawn
. I've tried looping over the pipedstderr
but it just send it through as one big string instead of line by line as they come in.In the Bun case,
cmd.stdout.on
doesn't exist and I can't find any way to replicate the node behaviour.Is this just something that is expected and I should be using the node library or should I be able to achieve the same behaviour via Bun?
Beta Was this translation helpful? Give feedback.
All reactions