小编Dar*_*mov的帖子

"系统找不到指定的文件"错误on process.Start();

我试图让进程响应为一个字符串,所以我可以在我的代码中的不同位置使用它,这是我到目前为止的解决方案:

const string ex1 = @"C:\Projects\MyProgram.exe ";
      const string ex2 = @"C:\Projects\ProgramXmlConfig.xml";


      Process process = new Process();
      process.StartInfo.WorkingDirectory = @"C:\Projects";
      process.StartInfo.FileName = "MyProgram.exe ";
      process.StartInfo.Arguments = ex2;
      process.StartInfo.Password = new System.Security.SecureString();
      process.StartInfo.UseShellExecute = false;
      process.StartInfo.RedirectStandardOutput = true;  

      try
      {
          process.Start();
          StreamReader reader = process.StandardOutput;
          string output = reader.ReadToEnd();
      }
      catch (Exception exception)
      {
          AddComment(exception.ToString());
      }
Run Code Online (Sandbox Code Playgroud)

但是当我跑步时,我得到:

"The system cannot find the file specified" error in process.Start(); without 
      process.StartInfo.UseShellExecute = false;
      process.StartInfo.RedirectStandardOutput = true;  
Run Code Online (Sandbox Code Playgroud)

代码运行正常,但它只是打开控制台窗口,所有进程响应都在那里,因此我不能将它用作字符串.

有谁知道为什么我得到这个错误或者可能是我的问题的不同解决方案?

c# process

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×1

process ×1