in src/TestFramework/Core/Adapters/ShellAdapterProxy.cs [272:346]
private int InvokeScript(string path, string arguments)
{
int exitCode = 0;
try
{
using (Process proc = new Process())
{
// For Linux/macOS, use the shell on current system
string wslPath = "/bin/bash";
// Detect current OS
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
if (isWindows)
{
// For Windows, WSL is needed
string winDir = Environment.GetEnvironmentVariable("WINDIR");
if (!string.IsNullOrEmpty(winDir))
{
if (Environment.Is64BitProcess)
{
wslPath = string.Format(@"{0}\System32\bash.exe", winDir);
}
else
{
wslPath = string.Format(@"{0}\Sysnative\bash.exe", winDir);
}
if (!File.Exists(wslPath))
{
TestSite.Assume.Fail("Windows Subsystem for Linux (WSL) is not installed.");
}
}
}
proc.StartInfo.FileName = wslPath;
proc.StartInfo.Arguments = String.Format("{0} {1}", path, arguments);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
List<string> wslEnvs = new List<string>();
// set ptfconfig properties as environment variables
foreach (string key in TestSite.Properties.AllKeys)
{
string envVar = "PTFProp_" + key.Replace(".", "_");
if (proc.StartInfo.EnvironmentVariables.ContainsKey(envVar))
{
proc.StartInfo.EnvironmentVariables.Remove(envVar);
}
proc.StartInfo.EnvironmentVariables.Add(envVar, TestSite.Properties[key]);
wslEnvs.Add(envVar + "/u");
}
// Set WSLENV to pass those environment variables into WSL
proc.StartInfo.EnvironmentVariables.Add("WSLENV", String.Join(":", wslEnvs));
proc.OutputDataReceived += new DataReceivedEventHandler(OutputDataReceivedHandler);
proc.ErrorDataReceived += new DataReceivedEventHandler(ErrorDataReceivedHandler);
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
proc.WaitForExit();
exitCode = proc.ExitCode;
proc.Close();
}
}
catch (System.ComponentModel.Win32Exception ex)
{
TestSite.Assume.Fail(ex.Message);
}
return exitCode;
}