Ed, Edd n Eddy
Ed, Edd n Eddy16mo ago

Migrating `Deno.run` to `Deno.command` with `readlines`

I had the following:
browserProcess = Deno.run({
cmd: buildArgs, // eg chrome exe path, then options
stderr: "piped",
stdout: "piped",
});
for await (const line of readLines(browserProcess.stderr!)) {
browserProcess = Deno.run({
cmd: buildArgs, // eg chrome exe path, then options
stderr: "piped",
stdout: "piped",
});
for await (const line of readLines(browserProcess.stderr!)) {
Now i'm wondering what the best way to do this with Deno.command is?
15 Replies
crowlKats
crowlKats16mo ago
child.readable.pipeThrough(new TextLineStream()) child being command.spawn() and TextLineStream from https://deno.land/std@0.198.0/streams/mod.ts?s=TextLineStream
Ed, Edd n Eddy
Ed, Edd n EddyOP16mo ago
🙏 thanks 🙂 been like 2+ years since ive touched deno so a lot has changed and not familiar with it all
crowlKats
crowlKats16mo ago
not that long, right 🤔 its been a while, but cant be 2 years
Ed, Edd n Eddy
Ed, Edd n EddyOP16mo ago
i dont think i touched deno/drashland shortly after my new job which was 2 years and one month ago so oculd be 1y 10m, though maybe i stopped later than i thought good to see your face though 😛
crowlKats
crowlKats16mo ago
yea same! I saw you every now and then in destiny's channel talking with Okku, but its been a while since that as well
Ed, Edd n Eddy
Ed, Edd n EddyOP16mo ago
was excited to see where destiny went, but wanna get back into deno again although: error: TS2339 [ERROR]: Property 'readable' does not exist on type 'ChildProcess'., deno v1.36.1, windows
crowlKats
crowlKats16mo ago
ah whoops stdout
Ed, Edd n Eddy
Ed, Edd n EddyOP16mo ago
still
Argument of type 'TextLineStream' is not assignable to parameter of type '{ writable: WritableStream<Uint8Array>; readable: ReadableStream<string>; }'.
Types of property 'writable' are incompatible.
Type 'WritableStream<string>' is not assignable to type 'WritableStream<Uint8Array>'.
Type 'string' is not assignable to type 'Uint8Array'.deno-ts(2345)
Argument of type 'TextLineStream' is not assignable to parameter of type '{ writable: WritableStream<Uint8Array>; readable: ReadableStream<string>; }'.
Types of property 'writable' are incompatible.
Type 'WritableStream<string>' is not assignable to type 'WritableStream<Uint8Array>'.
Type 'string' is not assignable to type 'Uint8Array'.deno-ts(2345)
:/
crowlKats
crowlKats16mo ago
Ah, first you have to pipe through a TextDecoderStream (built-in)
Ed, Edd n Eddy
Ed, Edd n EddyOP16mo ago
gotcha
crowlKats
crowlKats16mo ago
And then through the line stream
Ed, Edd n Eddy
Ed, Edd n EddyOP16mo ago
confused, where am i using TextLineStream?
const a = browserProcess.stdout.pipeThrough(new TextDecoderStream)
const b = browserProcess.stdout.pipeThrough(a);
const a = browserProcess.stdout.pipeThrough(new TextDecoderStream)
const b = browserProcess.stdout.pipeThrough(a);
oh it hink i see
crowlKats
crowlKats16mo ago
browserProcess.stdout.pipeThrough(new TextDecoderStream()).pipeThrough(new TextLineStream())
Ed, Edd n Eddy
Ed, Edd n EddyOP16mo ago
Thanks 🙏 dont suppose you'd know the ChildProcess equivelent of
this.#browser_process.stderr!.close();
this.#browser_process.stdout!.close();
this.#browser_process.close();
this.#browser_process.stderr!.close();
this.#browser_process.stdout!.close();
this.#browser_process.close();
? Tried the ai helper and got:
const stdoutReader = readerFromStreamReader(this.#browser_process.stdout.getReader())
await readAll(stdoutReader)
console.log(1)
const stderrReader = readerFromStreamReader(this.#browser_process.stderr.getReader())
await readAll(stderrReader)
this.#browser_process.kill("SIGINT")
const stdoutReader = readerFromStreamReader(this.#browser_process.stdout.getReader())
await readAll(stdoutReader)
console.log(1)
const stderrReader = readerFromStreamReader(this.#browser_process.stderr.getReader())
await readAll(stderrReader)
this.#browser_process.kill("SIGINT")
but it hangs on line 2 nvm got it sorted
wobsoriano
wobsoriano16mo ago
Hey @ededdneddy9188, do you have an example of your conversion of this? I tried this but it exits immediately https://discord.com/channels/684898665143206084/1131635673217118248/1149868174678958110