StreamReader路径自动更改 [英] StreamReader path changes automatically

查看:151
本文介绍了StreamReader路径自动更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些奇怪的问题(对我来说)。

I have some strange problem (for me).

有一个应用程序,它是一个Windows窗体应用程序firstapp.exe。
还有另外一个应用程序,它是Windows窗体应用程序太LAUNCHER.EXE。
和有一个名为SERVER.EXE控制台应用程序。

There is an application which is a windows form application "firstapp.exe". There is another application which is windows form application too "launcher.exe". And there is a console application with name "server.exe".

无论firstapp和发射器都在同一个目录。在该目录下还有一个配置文件夹中有一些其他文件

Both firstapp and launcher are in the same directory. In that directory there is also a "Config" folder with some other files in it.

这是我用来读取从firstapp config文件夹一个文件中的代码:

The code which I use to read one file from config folder in firstapp:

StreamReader reader = new StreamReader("Config\\launcher.txt");
string readed_config = reader.ReadToEnd();
reader.Close();

如果我运行启动器(使用的Process.Start)的firstapp应用程序一切顺利的罚款。
当我与控制台应用程序,这是不是在同一个目录firstapp我得到的代码(上面贴),该部分的目录未发现异常运行它。

If I run the firstapp application with launcher (using process.start) all goes fine. When I run it with console application, which is not in the same directory as firstapp I get the "directory not found exception" from that part of code (posted above).

我怎样才能解决这个问题?
为什么控制台应用程序添加自己的路径,这应该独立运行的其他应用程序?

How can I solve the problem? Why is console application adding its own path to another application which should run independently?

推荐答案

听起来像是你需要调用工作目录财产>的Process.Start

Sounds like you need to set the WorkingDirectory property of your Process before calling Process.Start.

string launcherPath = @"C:\SomePathToLauncher\Launcher.exe";
myProcess.StartInfo.FileName = launcherPath;
myProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(launcherPath);
myProcess.Start();

这篇关于StreamReader路径自动更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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