Files
bitburner-src/src/Terminal/commands/tail.ts
David Walker 8f4313b180 Revert "PIPE: Add pipe support for passing data into and out of terminal commands (#2395)" (#2524)
This reverts commit 92b8b58588.

Accidental merge on my part - the code is in decent shape, but isn't meant to go in for 3.0.
2026-02-22 11:28:10 -08:00

43 lines
1.8 KiB
TypeScript

import { Terminal } from "../../Terminal";
import { BaseServer } from "../../Server/BaseServer";
import { findRunningScripts, findRunningScriptByPid } from "../../Script/ScriptHelpers";
import { LogBoxEvents } from "../../ui/React/LogBoxManager";
import { hasScriptExtension } from "../../Paths/ScriptFilePath";
export function tail(commandArray: (string | number | boolean)[], server: BaseServer): void {
try {
if (commandArray.length < 1) {
Terminal.error("Incorrect number of arguments. Usage: tail [pid] or tail [scriptname] [arg1] [arg2]...");
} else if (typeof commandArray[0] === "string") {
const [rawName, ...args] = commandArray;
const path = Terminal.getFilepath(rawName);
if (!path) return Terminal.error(`Invalid filename: ${rawName}`);
if (!hasScriptExtension(path)) return Terminal.error(`Invalid file extension. Tail can only be used on scripts.`);
const candidates = findRunningScripts(path, args, server);
// if there's no candidate then we just don't know.
if (candidates === null) {
Terminal.error(`No script named ${path} with args ${JSON.stringify(args)} is running on the server`);
return;
}
// Just use the first one (if there are multiple with the same
// arguments, they can't be distinguished except by pid).
const next = candidates.values().next();
if (!next.done) {
LogBoxEvents.emit(next.value);
}
} else if (typeof commandArray[0] === "number") {
const runningScript = findRunningScriptByPid(commandArray[0]);
if (runningScript == null) {
Terminal.error(`No script with PID ${commandArray[0]} is running`);
return;
}
LogBoxEvents.emit(runningScript);
}
} catch (error) {
console.error(error);
Terminal.error(String(error));
}
}