Skip to main content

LensStudio:Subprocess.Writable

Class

Stream interface for writing to subprocess stdin.

Index

Example

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();

Extends

Methods

getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


write()

write(data): number

Write data to the stream and return the number of bytes written.

Parameters

ParameterType
datastring | Uint8Array<ArrayBufferLike>

Returns

number