LensStudio:Subprocess.Subprocess
ClassClass which allows you to trigger a subproccess outside of Lens Studio (e.g. a command line command).
Index
Properties
Methods
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
readonlycommand:string
The command for the subprocess.
onError
readonlyonError:signal1<number,void>
A handle for getting callback when a subprocess' state has errored.
onExit
readonlyonExit: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
readonlyonStart:signal0<void>
A handle for getting callback when a subprocess is started
onStateChange
readonlyonStateChange: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
A handle for getting callback when a subprocess' state has received stderr.
stdin
readonlystdin:Writable
A handle for getting callback when a subprocess' state has received stdin.
stdout
A handle for getting callback when a subprocess' state has received stdout.
Methods
create()
staticcreate(command,args,options):Subprocess
Create a subprocess.
Parameters
| Parameter | Type |
|---|---|
command | string |
args | string[] |
options | SpawnOptions |
Returns
Subprocess
getTypeName()
staticgetTypeName():string
Returns the type name of this class.
Returns
string
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object is of the specified type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object refers to the same instance as the given object.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
kill()
kill():
void
Kills a subprocess.
Returns
void
start()
start():
void
Starts a subprocess.
Returns
void