Update sample.txt
Browse files- sample.txt +130 -2
sample.txt
CHANGED
|
@@ -1,2 +1,130 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
using System.Diagnostics;
|
| 3 |
+
using System.IO;
|
| 4 |
+
|
| 5 |
+
namespace WslScriptRunner
|
| 6 |
+
{
|
| 7 |
+
class Program
|
| 8 |
+
{
|
| 9 |
+
static void Main(string[] args)
|
| 10 |
+
{
|
| 11 |
+
// ================= CONFIGURATION =================
|
| 12 |
+
// 1. Where is your script located inside Ubuntu?
|
| 13 |
+
// Use the absolute Linux path.
|
| 14 |
+
string wslScriptPath = "/home/silly98/heg_brep_inference/run_batch.sh";
|
| 15 |
+
|
| 16 |
+
// 2. Set your flag here (or determine via logic/user input)
|
| 17 |
+
bool isSingleFileMode = true;
|
| 18 |
+
|
| 19 |
+
// 3. Define your Windows paths (Files usually live on Windows C: drive)
|
| 20 |
+
string winStepFolder = @"C:\Users\FCI\Desktop\practice_step";
|
| 21 |
+
string winOutputFile = @"C:\Users\FCI\Desktop\output_step.xlsx";
|
| 22 |
+
string winSinglePart = @"C:\Users\FCI\Desktop\practice_step\0b5609107e7e40228d69d2b7419e7634.stp";
|
| 23 |
+
// =================================================
|
| 24 |
+
|
| 25 |
+
string wslCommandArguments;
|
| 26 |
+
|
| 27 |
+
try
|
| 28 |
+
{
|
| 29 |
+
// Build arguments based on the mode
|
| 30 |
+
if (isSingleFileMode)
|
| 31 |
+
{
|
| 32 |
+
// Mode 2: --single /path/to/one_part.step
|
| 33 |
+
string wslPartPath = ToWslPath(winSinglePart);
|
| 34 |
+
// REMOVE the single quotes from around {wslPartPath}
|
| 35 |
+
wslCommandArguments = $"-e bash {wslScriptPath} --single {wslPartPath}";
|
| 36 |
+
|
| 37 |
+
Console.WriteLine($"[Mode] Single File: {wslPartPath}");
|
| 38 |
+
}
|
| 39 |
+
else
|
| 40 |
+
{
|
| 41 |
+
// Mode 1: /path/to/step_folder /path/to/output.xlsx
|
| 42 |
+
string wslFolderPath = ToWslPath(winStepFolder);
|
| 43 |
+
string wslOutputPath = ToWslPath(winOutputFile);
|
| 44 |
+
|
| 45 |
+
// REMOVE the single quotes from around {wslFolderPath} and {wslOutputPath}
|
| 46 |
+
wslCommandArguments = $"-e bash {wslScriptPath} {wslFolderPath} {wslOutputPath}";
|
| 47 |
+
|
| 48 |
+
Console.WriteLine($"[Mode] Batch Folder: {wslFolderPath}");
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
// Run the command
|
| 52 |
+
RunWslCommand(wslCommandArguments);
|
| 53 |
+
}
|
| 54 |
+
catch (Exception ex)
|
| 55 |
+
{
|
| 56 |
+
Console.WriteLine($"Critical Error: {ex.Message}");
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
Console.WriteLine("\nPress any key to exit...");
|
| 60 |
+
Console.ReadKey();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/// <summary>
|
| 64 |
+
/// Executes a command in WSL (Ubuntu) and prints the output.
|
| 65 |
+
/// </summary>
|
| 66 |
+
static void RunWslCommand(string arguments)
|
| 67 |
+
{
|
| 68 |
+
ProcessStartInfo psi = new ProcessStartInfo
|
| 69 |
+
{
|
| 70 |
+
FileName = "wsl.exe",
|
| 71 |
+
Arguments = arguments,
|
| 72 |
+
RedirectStandardOutput = true,
|
| 73 |
+
RedirectStandardError = true,
|
| 74 |
+
UseShellExecute = false,
|
| 75 |
+
CreateNoWindow = true
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
using (Process process = new Process { StartInfo = psi })
|
| 79 |
+
{
|
| 80 |
+
Console.WriteLine("Initializing WSL process...");
|
| 81 |
+
process.Start();
|
| 82 |
+
|
| 83 |
+
// Read output streams
|
| 84 |
+
string output = process.StandardOutput.ReadToEnd();
|
| 85 |
+
string error = process.StandardError.ReadToEnd();
|
| 86 |
+
|
| 87 |
+
process.WaitForExit();
|
| 88 |
+
|
| 89 |
+
// Display results
|
| 90 |
+
if (!string.IsNullOrEmpty(output))
|
| 91 |
+
{
|
| 92 |
+
Console.WriteLine("------------- UBUNTU OUTPUT -------------");
|
| 93 |
+
Console.WriteLine(output);
|
| 94 |
+
Console.WriteLine("-----------------------------------------");
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
if (!string.IsNullOrEmpty(error))
|
| 98 |
+
{
|
| 99 |
+
Console.ForegroundColor = ConsoleColor.Red;
|
| 100 |
+
Console.WriteLine("------------- UBUNTU ERRORS -------------");
|
| 101 |
+
Console.WriteLine(error);
|
| 102 |
+
Console.ResetColor();
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
Console.WriteLine($"Process finished with Exit Code: {process.ExitCode}");
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/// <summary>
|
| 110 |
+
/// Converts a Windows path (C:\Folder\File.txt) to a WSL path (/mnt/c/Folder/File.txt)
|
| 111 |
+
/// </summary>
|
| 112 |
+
static string ToWslPath(string windowsPath)
|
| 113 |
+
{
|
| 114 |
+
if (string.IsNullOrWhiteSpace(windowsPath)) return "";
|
| 115 |
+
|
| 116 |
+
// 1. Replace backslashes with forward slashes
|
| 117 |
+
string wslPath = windowsPath.Replace("\\", "/");
|
| 118 |
+
|
| 119 |
+
// 2. Handle the drive letter (e.g., "C:" becomes "/mnt/c")
|
| 120 |
+
// Check if the path starts with a drive letter (e.g. "C:/")
|
| 121 |
+
if (wslPath.Length > 1 && wslPath[1] == ':')
|
| 122 |
+
{
|
| 123 |
+
char driveLetter = char.ToLower(wslPath[0]);
|
| 124 |
+
wslPath = $"/mnt/{driveLetter}{wslPath.Substring(2)}";
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
return wslPath;
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
}
|