在其他PC上运行.exe时获取文件未找到错误 [英] Getting a file not found error when .exe is runned on other PC

查看:99
本文介绍了在其他PC上运行.exe时获取文件未找到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在c#中创建了一个应用程序,它在cmd中执行文件并将输出存储在文本文件中然后显示它。这在一台PC上运行良好,但如果我把它带到其他PC,它会给我找不到文件错误请帮帮我这个



我尝试过:



I have created a application in c# which execute file in cmd and store the output in text file and then displays it.This runs well on one PC ,but if i take it to some other PC it gives me file not found error .Please help me out in this

What I have tried:

strCmdText = "/C"+textBox1.Text + " --gtest_list_tests>>PathForGtest.txt";
           System.Diagnostics.Process.Start("CMD.exe", strCmdText);




string h=Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"PathForGtest.txt");
            
            System.IO.StreamReader file = new System.IO.StreamReader (h);

           
            while ((fileLine = file.ReadLine()) != null)
            {
                if ((fileLine.EndsWith(".")))
                {
                    buffer = fileLine;
                    continue;
                }
                else
                {
                    line = fileLine.Trim();
                    propertyNode = propertyNode + 1;
                }
                propertyName = buffer + line;

推荐答案

要做的第一件事是找出它是哪个文件抱怨:使用 try ... catch 块来捕获Exception对象并报告它的错误,完成任何内部异常细节。



当你知道错误来自代码的位置时,你可以开始查看原因 - 但找出哪个文件是第一优先级。

直到你可以隔离它,你只是在猜测。我们不能为你做到这一点!
The first thing to do is find out which file it is complaining about: use try...catch blocks to catch the Exception object and report it's error, complete with any inner exception detail.

When you know that, and where in your code the error is coming from, you can start looking at why - but finding out which file is the first priority.
Until you can isolate that, you are just guessing. And we can't do that for you!


这篇关于在其他PC上运行.exe时获取文件未找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆