Bun Shell - exit code and await for (const chunk of $
….chunks())
#8324
-
Hi! Thanks for releasing Bun Shell! I looked at the types and I only found this way to extract the exit code while also using one of the helpers, like import { $ } from 'bun';
import { expect } from 'bun:test';
const process = $`bun -e ${'const d = +performance.now().toString().slice(-2); console.log(d); process.exit(d);'}`;
const text = await process.text();
const { exitCode } = await process;
expect(exitCode).toEqual(+text); I verify this doesn't run the command two separate times by checking the exit code and the output match the same Is this an okay way to get the exit code while also using one of the helpers, like When I did
Also, I think the helpers are buffered, right? I was curious about this in regard to the import { $ } from 'bun';
for await (const line of $`bun -e "while (true) { console.log(Date.now()); await Bun.sleep(1000); }"`.lines()) {
console.log({ line });
} This code waits forever. Is there a way And related to that, if that is possible and will come, can we also get for await (const chunk of $`my-process`.chunks()) {
// Process the flushed chunk here
} Thanks! @zackradisic you're probably the best person to ask this as the shell PR author I believe. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think we should make helpers like
Yep, at some point we will allow stdout/stderr to be consumed as ReadableStreams |
Beta Was this translation helpful? Give feedback.
I think we should make helpers like
.text()
and.line()
be on the returnedShellOutput
so theShellPromise
doesn't have to be awaited againYep, at some point we will allow stdout/stderr to be consumed as ReadableStreams