加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – “系统找不到指定的文件”错误on process.Start();

发布时间:2020-12-15 18:21:43 所属栏目:百科 来源:网络整理
导读:我试图让进程响应为一个字符串,所以我可以在我的代码中的不同位置使用它,这是我到目前为止的解决方案: const string ex1 = @"C:ProjectsMyProgram.exe "; const string ex2 = @"C:ProjectsProgramXmlConfig.xml"; Process process = new Process(); pro
我试图让进程响应为一个字符串,所以我可以在我的代码中的不同位置使用它,这是我到目前为止的解决方案:
const string ex1 = @"C:ProjectsMyProgram.exe ";
      const string ex2 = @"C:ProjectsProgramXmlConfig.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());
      }

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

06001

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

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

解决方法

我怀疑问题是您指定的文件名是相对于您的工作目录的,并且您希望Process.Start在启动进程时查看它 – 我不相信当UseShellExecute为false时它会这样运行.尝试只指定要启动的进程的绝对文件名:
process.StartInfo.FileName = @"C:ProjectsMyProgram.exe";

请注意,我还从为FileName属性分配的字符串的末尾删除了空格 – 完全有可能也是这个问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读