Files
webshell/src/program/Loadprg.ts
2026-05-18 19:22:34 +02:00

30 lines
796 B
TypeScript

import type { Item } from '../fs/Item'
import type { Shell } from '../shell/Shell'
import type { SimpleStream } from '../utils/SimpleStream'
import { Program } from './Program'
export class Loadprg extends Program {
private shell: Shell
constructor(shell: Shell) {
super()
this.shell = shell
}
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, workdir: Item, args: string[]): Promise<number> {
const javascript = args.slice(2).join(' ')
try {
const program = eval(javascript)
this.shell.LoadProgram(new program(), args[1])
} catch (e) {
stdout.emit(`${String(e)}\n`)
stdout.emit(`${String((e as Error).stack)}\n`)
return 1
}
return 0
}
}