Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# PSExec挂起运行测试,但在调试会话中工作正常_C#_Mbunit_Psexec - Fatal编程技术网

C# PSExec挂起运行测试,但在调试会话中工作正常

C# PSExec挂起运行测试,但在调试会话中工作正常,c#,mbunit,psexec,C#,Mbunit,Psexec,当我在调试模式下运行代码时,测试就完成了,当我在运行测试中运行它时,ps exec似乎挂起并且从不返回,我也将kill放在适当的位置,但它从未完成 为什么这在调试时完成,而不是在运行模式下完成 这里有什么我遗漏的愚蠢的东西吗 public class RemoteExeInvokerTask :IQaTask { public string TargetHostName { get; set; } public string TargetHostUserName { get; set;

当我在调试模式下运行代码时,测试就完成了,当我在运行测试中运行它时,ps exec似乎挂起并且从不返回,我也将kill放在适当的位置,但它从未完成

为什么这在调试时完成,而不是在运行模式下完成

这里有什么我遗漏的愚蠢的东西吗

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;
  }

例如,基本上将变量前面有“\”双斜杠的地方替换为@

what if you change string 
quotedArgs = string.Format("\\\\{0} -u {1} -p {2} {3} " 
像这样读
string quotedArgs=string.Format(@“{0}-u{1}-p{2}{3}” 或

也代替 字符串psExecUtility=Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)+“\PsTools\psExec.exe”

像这样的事情

string psExecUtility =  Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "@PathandExName 

//它应该是这个“\PsTools\psExec.exe”的变量;

如果将字符串quotedArgs=string.Format(“\\\\{0}-u{1}-p{2}{3}”更改为字符串quotedArgs=string.Format(@{0}-u{1}-p{2}{3})或字符串quotedArgs=string.Format({0}-u{1}-p{3})@TargetHostName、@TargetHostUserName、@TargetPassword、TargetExecutableWithParams4I建议使用
Path.Combine(字符串、字符串)
,特别是针对您的
字符串psExecUtility=
代码。问题在于processInfo.UseShellExecute=false,如果我们注释掉位并忽略StanderError和StandardOutput,它就可以正常工作,只有当我们想要读取它时,它才会死机。说它工作非常间歇。因此这可能是Win的问题7 64位shell。有什么解决方案吗?echo命令可以挂起psexec吗?这不起作用。尝试了所有组合,但无效。当使用i将其更改为string.Format(“{0}-u{1}-p{2}{3}”时,我得到一个错误,即参数无效。更改i做了更改以执行路径。组合。似乎也不起作用。
string quotedArgs = string.Format("{0} -u {1} -p {2}{3} ",
@TargetHostName,
@TargetHostUserName,
@TargetPassword,
@TargetExecutableWithParams4
string psExecUtility =  Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "@PathandExName