TangJieHaoT
Denoβ€’17mo agoβ€’
2 replies
TangJieHao

WritableSteam not opening.

    constructor() {
        this.command = new Deno.Command(this.exec, {
            args: ["analysis", "-model", this.model, "-config", this.config],
            stdin: "piped",
            stdout: "piped",
            stderr: "piped",
        });

        this.AI = this.command.spawn();
        this.stdin = this.AI.stdin.getWriter();
        this.stdout = this.AI.stdout.getReader();
        this.stderr = this.AI.stderr.getReader();
    }

    async writeToStdin(data: string): Promise<void> {
        const encoder = new TextEncoder();
        const encoded = encoder.encode(data);
        await this.stdin.write(encoded);
    }

    async readFromStdout(): Promise<string> {
        let buffer = "";
        const decoder = new TextDecoder();
        while (true) {
            const { value, done } = await this.stdout.read();
            if (done) {
                return buffer.trim();
            }

            buffer += decoder.decode(value, { stream: true });

        }
    }


I seem to only be able to write to the stdin once.
I have tried closing and getting a new getWriter with every new write call but I get same issue that stdin is closed or is closing
Was this page helpful?