从c#运行exe文件时出现问题
当我执行 exe 文件 (PVFProject15.exe) 时,它从输入文件 (inputFile.txt) 读取数据并将结果打印到另一个文件 (outputFile.txt) 中。当我双击该exe文件时,它运行良好;它打开控制台窗口,该窗口在创建输出文件之前一直保持打开状态。但是,当我从 c# 运行 (PVFProject15.exe) 时,控制台窗口打开和关闭得非常快,并且永远不会创建输出文件。
我非常感谢您的帮助,因为我一整天都在努力解决这个问题,但从未找到答案。下面是我的代码。
private void button1_Click(object sender, EventArgs e)
{
Process runFortran = new Process();
try
{
runFortran.StartInfo.FileName = "C:\\temp\\trial\\PVFProject15.exe";
runFortran.Start();
runFortran.WaitForExit();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
先感谢您。
萨法阿
When I execute an exe file (PVFProject15.exe), it reads the data from an input file (inputFile.txt) and print the results in another file (outputFile.txt). The exe file works well when I double click it; It opens the console window which stays opened until the output file is created. However, when I run (PVFProject15.exe) from c#, the console window opens and closes very quickly and the output file is never created.
I would really appreciate your help since I have been working to fix this for a whole day and never found the answer. Here is my code below.
private void button1_Click(object sender, EventArgs e)
{
Process runFortran = new Process();
try
{
runFortran.StartInfo.FileName = "C:\\temp\\trial\\PVFProject15.exe";
runFortran.Start();
runFortran.WaitForExit();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
Thank you in advance.
Safaa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能 PVFProject15.exe 需要将当前目录设置为 C:\temp\Trial
Probably PVFProject15.exe needs current directory to be set to C:\temp\trial
如果
PVFProject15.exe
使用相对路径写入文件,请在启动主程序引导程序的目录中查找outputFile.txt
。If
PVFProject15.exe
writes to file using relative path, look foroutputFile.txt
in directory from which you start your main program-bootstrapper.当我尝试从基于 C# 的软件启动一些 .exe 和 .hta 时,我也遇到了同样的问题。
我开始寻找迈克·莫扎耶夫的解决方案和答案,为我指明了正确的方向。
在您的代码中您需要使用:
StartInfo.WorkingDirectory = Convert.ToString( System.IO.Directory.GetParent(appPath));
所以代码必须是这样的:
I also meet with same problem, when I try start some .exe and .hta from my C# based software.
I start to looking for solution and answer of Mike Mozhaev get to me right direction.
In your code you need to use:
StartInfo.WorkingDirectory = Convert.ToString( System.IO.Directory.GetParent(appPath));
So code have to be like this: