Move file existence check and improve process output handling

This commit is contained in:
Stone_Red
2026-03-06 00:09:11 +01:00
parent 246e05dcd9
commit 1872c4fb35
3 changed files with 11 additions and 11 deletions
+7
View File
@@ -1,9 +1,16 @@
using System; using System;
using System.IO;
using YesNt.Interpreter.Runtime; using YesNt.Interpreter.Runtime;
if (args.Length == 1) if (args.Length == 1)
{ {
if (!File.Exists(args[0]))
{
Console.WriteLine("File not found: " + args[0]);
return;
}
YesNtInterpreter interpreter = new YesNtInterpreter(); YesNtInterpreter interpreter = new YesNtInterpreter();
interpreter.Execute(args[0]); interpreter.Execute(args[0]);
} }
@@ -449,18 +449,11 @@ public class YesNtInterpreter
if (!File.Exists(path)) if (!File.Exists(path))
{ {
Console.WriteLine($"File \"{path}\" not found!");
return false; return false;
} }
string[] lines = File.ReadAllLines(path); string[] lines = File.ReadAllLines(path);
if (lines.Length <= 0)
{
Console.WriteLine($"File \"{path}\" is empty!");
return false;
}
runtimeInfo.WorkingDirectory = Path.GetDirectoryName(path); runtimeInfo.WorkingDirectory = Path.GetDirectoryName(path);
for (int i = 0; i < lines.Length; i++) for (int i = 0; i < lines.Length; i++)
@@ -64,7 +64,7 @@ internal class SystemStatements : StatementRuntimeInformation
} }
} }
private static void Process_ErrorDataReceived(Utilities.DataReceivedEventArgs e, Stack<string> outputStack) private void Process_ErrorDataReceived(Utilities.DataReceivedEventArgs e, Stack<string> outputStack)
{ {
if (string.IsNullOrWhiteSpace(e.Data)) if (string.IsNullOrWhiteSpace(e.Data))
{ {
@@ -72,10 +72,10 @@ internal class SystemStatements : StatementRuntimeInformation
} }
outputStack.Push(e.Data.ToSafeString()); outputStack.Push(e.Data.ToSafeString());
Console.Write("Error: " + e.Data); RuntimeInfo.Write("Error: " + e.Data);
} }
private static void Process_OutputDataReceived(Utilities.DataReceivedEventArgs e, Stack<string> outputStack) private void Process_OutputDataReceived(Utilities.DataReceivedEventArgs e, Stack<string> outputStack)
{ {
if (string.IsNullOrWhiteSpace(e.Data)) if (string.IsNullOrWhiteSpace(e.Data))
{ {
@@ -83,7 +83,7 @@ internal class SystemStatements : StatementRuntimeInformation
} }
outputStack.Push(e.Data.ToSafeString()); outputStack.Push(e.Data.ToSafeString());
Console.Write(e.Data); RuntimeInfo.Write(e.Data);
} }
private void StartProcess(string name, string args) private void StartProcess(string name, string args)