我有一些奇怪的问题(对我而言).
有一个应用程序是Windows窗体应用程序"firstapp.exe".还有另一个应用程序,也是Windows窗体应用程序"launcher.exe".并且有一个名为"server.exe"的控制台应用程序.
firstapp和启动器都在同一目录中.在该目录中还有一个"Config"文件夹,其中包含一些其他文件.
我用来从firstapp的config文件夹中读取一个文件的代码:
StreamReader reader = new StreamReader("Config\\launcher.txt");
string readed_config = reader.ReadToEnd();
reader.Close();
Run Code Online (Sandbox Code Playgroud)
如果我使用启动器(使用process.start)运行firstapp应用程序,一切都很顺利.当我使用控制台应用程序运行它时,它与firstapp不在同一目录中,我从代码部分(上面发布)中获取"目录未找到异常".
我该如何解决这个问题?为什么控制台应用程序将自己的路径添加到应该独立运行的另一个应用程
听起来你需要在调用之前设置Process 的WorkingDirectory属性Process.Start.
string launcherPath = @"C:\SomePathToLauncher\Launcher.exe";
myProcess.StartInfo.FileName = launcherPath;
myProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(launcherPath);
myProcess.Start();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
997 次 |
| 最近记录: |