When i run the code in debug mode the test completes, when i run it in a run test the ps exec seems to hang and never return i put the kill in place also but it never finished.
why does this complete on debug but not in a run mode.
is there anything silly here which i am missing?
public class RemoteExeInvokerTask :IQaTask
{
public string TargetHostName { get; set; }
public string TargetHostUserName { get; set; }
public string TargetPassword { get; set; }
public string TargetExecutableWithParams { get; set; }
public string DoWork()
{
string psExecUtility = Path.GetDirectoryName(Assembly
.GetExecutingAssembly()
.Location)
+ "\\PsTools\\psExec.exe";
string quotedArgs = string.Format("\\\\{0} -u {1} -p {2} {3} ",
TargetHostName,
TargetHostUserName,
TargetPassword,
TargetExecutableWithParams);
ProcessStartInfo processInfo = new ProcessStartInfo(psExecUtility, quotedArgs);
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
processInfo.UseShellExecute = false;
processInfo.CreateNoWindow = true;
Process process = Process.Start(processInfo);
process.WaitForExit();
string error = process.StandardError.ReadToEnd();
string output = process.StandardOutput.ReadToEnd();
int exitCode = process.ExitCode;
process.Close();
if (Process.GetProcessById(process.Id) != null)
{
process.Kill();
}
if (exitCode <= -1)
{
string errorMessage = string.Format("Process Exited with ErrorMessge {0} {1} "
+ "OutputMessage {2}",
error,
Environment.NewLine,
output);
throw new MyApplicationException(errorMessage);
}
return output;
}
Test code.
[Test]
[ExpectedException(typeof(MyApplicationException))]
[Description("Expect a exception message form the Server.")]
public void RemoteInvokeOfJobWrapperFromCommandLine()
{
RemoteExeInvokerTask task = new RemoteExeInvokerTask {
TargetHostName = "Serverd02",
TargetHostUserName = @"corp\username",
TargetPassword = @"password",
TargetExecutableWithParams = @" E:\D01\Home.Framework.JobExecutionEngine\Home.Framework.JobexecutionEngine.exe 99999 1"};
string value = task.DoWork();
Assert.IsNotNull(value);
}