Stream interface for writing to subprocess stdin.
const Subprocess = await import('LensStudio:Subprocess'); // Writable is the stdin stream of a Subprocess. // Method: write(data: Uint8Array | string) => number (bytes written) const proc = Subprocess.Subprocess.create('cat', [], {} as any); this.connections.push( proc.stdout.connect((data: Editor.Buffer) => { console.log(`cat echoed back: ${data.toString().length} bytes`); }) ); this.connections.push( proc.onExit.connect((code: number) => { console.log(`cat exited with code: ${code}`); }) ); proc.start(); // Write a string to stdin; returns number of bytes written const bytesWritten = proc.stdin.write('Hello from Writable\n'); console.log(`Writable.write returned: ${bytesWritten} bytes written`); // Can also write Uint8Array const binaryData = new Uint8Array([72, 101, 108, 108, 111, 10]); // "Hello\n" const bytesWritten2 = proc.stdin.write(binaryData); console.log(`Writable.write (binary): ${bytesWritten2} bytes written`); // Kill after writing proc.kill(); Copy
const Subprocess = await import('LensStudio:Subprocess'); // Writable is the stdin stream of a Subprocess. // Method: write(data: Uint8Array | string) => number (bytes written) const proc = Subprocess.Subprocess.create('cat', [], {} as any); this.connections.push( proc.stdout.connect((data: Editor.Buffer) => { console.log(`cat echoed back: ${data.toString().length} bytes`); }) ); this.connections.push( proc.onExit.connect((code: number) => { console.log(`cat exited with code: ${code}`); }) ); proc.start(); // Write a string to stdin; returns number of bytes written const bytesWritten = proc.stdin.write('Hello from Writable\n'); console.log(`Writable.write returned: ${bytesWritten} bytes written`); // Can also write Uint8Array const binaryData = new Uint8Array([72, 101, 108, 108, 111, 10]); // "Hello\n" const bytesWritten2 = proc.stdin.write(binaryData); console.log(`Writable.write (binary): ${bytesWritten2} bytes written`); // Kill after writing proc.kill();
Protected
Snap Hidden
Returns the name of this object's type.
Returns true if the object is of the specified type.
Returns true if this object refers to the same instance as the given object.
Write data to the stream and return the number of bytes written.
Stream interface for writing to subprocess stdin.
Example