|
8 | 8 | using System.Diagnostics; |
9 | 9 | using System.Text; |
10 | 10 | using System.Data; |
| 11 | +using System.Runtime.InteropServices; |
11 | 12 |
|
12 | 13 | namespace Microsoft.Protocols.TestTools |
13 | 14 | { |
@@ -210,7 +211,7 @@ private string LookupScript(string methodname) |
210 | 211 | } |
211 | 212 | } |
212 | 213 |
|
213 | | - private string BuildScriptArguments() |
| 214 | + private string BuildScriptArguments() |
214 | 215 | { |
215 | 216 | StringBuilder arguments = new StringBuilder(); |
216 | 217 | arguments.Append(BuildInArguments()); |
@@ -253,24 +254,32 @@ private int InvokeScript(string path, string arguments) |
253 | 254 | { |
254 | 255 | using (Process proc = new Process()) |
255 | 256 | { |
| 257 | + // For Linux/macOS, use the shell on current system |
256 | 258 | string wslPath = "/bin/bash"; |
257 | | - string winDir = Environment.GetEnvironmentVariable("WINDIR"); |
258 | | - if(!string.IsNullOrEmpty(winDir)) |
259 | | - { |
260 | | - if (Environment.Is64BitProcess) |
261 | | - { |
262 | | - wslPath = string.Format(@"{0}\System32\bash.exe", winDir); |
263 | | - } |
264 | | - else |
265 | | - { |
266 | | - wslPath = string.Format(@"{0}\Sysnative\bash.exe", winDir); |
267 | | - } |
268 | 259 |
|
269 | | - if (!File.Exists(wslPath)) |
| 260 | + // Detect current OS |
| 261 | + bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); |
| 262 | + if (isWindows) |
| 263 | + { |
| 264 | + // For Windows, WSL is needed |
| 265 | + string winDir = Environment.GetEnvironmentVariable("WINDIR"); |
| 266 | + if (!string.IsNullOrEmpty(winDir)) |
270 | 267 | { |
271 | | - TestSite.Assume.Fail("Windows Subsystem for Linux (WSL) is not installed."); |
| 268 | + if (Environment.Is64BitProcess) |
| 269 | + { |
| 270 | + wslPath = string.Format(@"{0}\System32\bash.exe", winDir); |
| 271 | + } |
| 272 | + else |
| 273 | + { |
| 274 | + wslPath = string.Format(@"{0}\Sysnative\bash.exe", winDir); |
| 275 | + } |
| 276 | + |
| 277 | + if (!File.Exists(wslPath)) |
| 278 | + { |
| 279 | + TestSite.Assume.Fail("Windows Subsystem for Linux (WSL) is not installed."); |
| 280 | + } |
272 | 281 | } |
273 | | - } |
| 282 | + } |
274 | 283 |
|
275 | 284 | proc.StartInfo.FileName = wslPath; |
276 | 285 | proc.StartInfo.Arguments = String.Format("{0} {1}", path, arguments); |
|
0 commit comments