Skip to content

Instantly share code, notes, and snippets.

@julesx

julesx/program.cs

Created Jun 21, 2018
Embed
What would you like to do?
command line work
private static void RunSelectedTests(List<String> apexClasses)
{
using (var cmdProcess = InitCmdProcess())
{
using (StreamWriter cmdProcessWriter = cmdProcess.StandardInput)
{
var selectedTests = string.Join(",", apexClasses);
cmdProcessWriter.WriteLine("sfdx force:apex:test:run -n " + selectedTests);// + " -d \"c:\\my stuff\\logs\"");
}
String output;
while ((output = cmdProcess.StandardOutput.ReadLine()) != null)
{
if (output.Contains("retrieve test results"))
{
Regex regex = new Regex("([\"'])(?:(?=(\\\\?))\\2.)*?\\1");
Match match = regex.Match(output);
if (match.Success)
{
GetTestResults(match.Value.Trim('"'), apexClasses);
}
}
else
{
Console.Error.WriteLine(output);
}
}
}
}
private static Process InitCmdProcess()
{
var cmdProcess = new Process();
cmdProcess.StartInfo.FileName = "cmd.exe";
cmdProcess.StartInfo.RedirectStandardOutput = true;
cmdProcess.StartInfo.RedirectStandardInput = true;
cmdProcess.StartInfo.UseShellExecute = false;
cmdProcess.Start();
return cmdProcess;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.