From 61dcde1920a3017c3561193685cdc147edf9d2f3 Mon Sep 17 00:00:00 2001 From: nidropakshin2 Date: Thu, 13 Mar 2025 11:23:52 +0300 Subject: [PATCH] redirecting in/out to files using flags --- source/interpr.d | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/source/interpr.d b/source/interpr.d index b7d2477..903e31f 100644 --- a/source/interpr.d +++ b/source/interpr.d @@ -42,6 +42,33 @@ int main (string [] args) pos += 1; steps = args[pos].to !(int); } + else if (args[pos] == "-i") + { + pos += 1; + try + { + auto input = File(args[pos], "r"); + stdin = input; + } + catch (Exception e) + { + stderr.writefln("Cannot find input file \"%s\", using stdin", args[pos]); + } + + } + else if (args[pos] == "-o") + { + pos += 1; + try + { + auto output = File(args[pos], "w"); + stdout = output; + } + catch (Exception e) + { + stderr.writefln("Cannot find output file \"%s\", using stdout", args[pos]); + } + } else { fileName = args[pos];