mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-09 16:06:08 +02:00
Move file existence check and improve process output handling
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user