3. 표준출력(보여주기)과 오류(stderr) 받아오기
표준출력(보여주기)과 오류(stderr) 받아오기
Section titled “표준출력(보여주기)과 오류(stderr) 받아오기”약속 코드에서 보여주기로 출력된 값은 기본적으로는 console.log로 출력됩니다.
config 객체를 사용하여 출력 방식을 변경할 수 있습니다.
import { SessionConfig, YaksokSession } from "@dalbit-yaksok/core";
const code = `"안녕, 세상!" 보여주기`;
const config: Partial<SessionConfig> = { // [!code highlight] stdout(message: string) { // [!code highlight] alert("[보여주기] " + message); // [!code highlight] }, // [!code highlight]}; // [!code highlight]
const session = new YaksokSession(config);session.addModule("main", code);await session.runModule("main");오류(stderr) 출력하기
Section titled “오류(stderr) 출력하기”stdout과 마찬가지로 stderr도 출력 방식을 변경할 수 있습니다. 기본적으로
stderr는 console.error로 출력됩니다.
import { SessionConfig, YaksokSession } from "@dalbit-yaksok/core";
const code = `"안녕, 세상!" / 10 보여주기`; // 오류가 발생할 코드
const config: Partial<SessionConfig> = { // [!code highlight] stderr(message: string) { // [!code highlight] alert("[오류] " + message); // [!code highlight] }, // [!code highlight]}; // [!code highlight]
const session = new YaksokSession(config);session.addModule("main", code);await session.runModule("main");자세한 내용은 다음 문서를 참조하세요: