Skip to main content

LensStudio:Subprocess.Subprocess

Class

Class which allows you to trigger a subproccess outside of Lens Studio (e.g. a command line command).

Index

Example

const Subprocess = await import('LensStudio:Subprocess');

// --- Async spawn via Subprocess.create ---
// Subprocess.create(command, args, options) returns a Subprocess instance.
// Call .start() to begin execution. Connect signals for events.
const proc = Subprocess.Subprocess.create('echo', ['async hello'], {} as any);

this.connections.push(
proc.onStart.connect(() => {
console.log(`Subprocess started: ${proc.command}`);
})
);

this.connections.push(
proc.stdout.connect((data: Editor.Buffer) => {
console.log(`stdout received: ${data.toString().length} bytes`);
})
);

this.connections.push(
proc.stderr.connect((data: Editor.Buffer) => {
console.log(`stderr received: ${data.toString().length} bytes`);
})
);

this.connections.push(
proc.onExit.connect((exitCode: number, exitStatus: number) => {
console.log(`Subprocess exited: code=${exitCode}, status=${exitStatus}`);
})
);

this.connections.push(
proc.onError.connect((errorCode: number) => {
console.log(`Subprocess error: ${errorCode}`);
})
);

this.connections.push(
proc.onStateChange.connect((state: number) => {
// 0=NotRunning, 1=Starting, 2=Running
console.log(`Subprocess state changed: ${state}`);
})
);

proc.start();

// --- Synchronous spawn ---
const syncResult = Subprocess.spawnSync('echo', ['sync hello'], {} as any);
console.log(`spawnSync exitCode: ${syncResult.exitCode}`);

// --- stdin (Writable) ---
// proc.stdin is a Writable; use proc.stdin.write(data) to send input.
console.log(`stdin available: ${proc.stdin !== undefined}`);

Extends

Properties

command

readonly command: string

The command for the subprocess.


onError

readonly onError: signal1<number, void>

A handle for getting callback when a subprocess' state has errored.


onExit

readonly onExit: signal2<number, number, void>

A handle for getting callback when a subprocess' state has exited.

Callback will receive two arguments in order: Exit code (usually 0 means success) Exit status (0 on normal exit, 1 on crash)


onStart

readonly onStart: signal0<void>

A handle for getting callback when a subprocess is started


onStateChange

readonly onStateChange: signal1<number, void>

A handle for getting callback when a subprocess' state has changed.

Callback will receive a number describing a state.

Possible states: Not running 0 Starting 1 Running 2


stderr

readonly stderr: signal1<Buffer, void>

A handle for getting callback when a subprocess' state has received stderr.


stdin

readonly stdin: Writable

A handle for getting callback when a subprocess' state has received stdin.


stdout

readonly stdout: signal1<Buffer, void>

A handle for getting callback when a subprocess' state has received stdout.

Methods

create()

static create(command, args, options): Subprocess

Create a subprocess.

Parameters

ParameterType
commandstring
argsstring[]
optionsSpawnOptions

Returns

Subprocess


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


kill()

kill(): void

Kills a subprocess.

Returns

void


start()

start(): void

Starts a subprocess.

Returns

void