如何在C#中执行exe文件 [英] How to execute an exe file in C#

查看:117
本文介绍了如何在C#中执行exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行POS标记器并使用此代码



i am trying to run a POS tagger and i m using this code

private void button1_Click(object sender, EventArgs e)
{
    Process myProcess = new Process();
    
    try
    {
        myProcess.StartInfo.UseShellExecute = false;
        
        myProcess.StartInfo.FileName = "C:\\POS_Tagger\\Tagger.exe";
        myProcess.StartInfo.CreateNoWindow = true;
        myProcess.Start();
    
    }
    catch (Exception a)
    {
        textBox1.Text = a.Message;
    }

}





此代码中没有错误但它没有执行我的文件。

此文件从INPUT.txt文件获取输入,并将结果存储在RESULT.txt中。 INPUT.txt和RESULT.txt文件都存在于POS_Tagger文件夹中,此Tagger.exe也存在于此文件中。



there is no error in this code but its not executing my file.
This file takes input from an INPUT.txt file and stores the result in RESULT.txt. Both INPUT.txt and RESULT.txt files are present in POS_Tagger folder where this Tagger.exe is also present.

推荐答案

评论下面的行,并检查您是否可以看到Tagger。 exe运行与否

comment below line and check you can see Tagger.exe running or not
//myProcess.StartInfo.CreateNoWindow = true;



如果它运行在那里处理Tagger.exe中的文件时可能会出错,如果你可以使用消息框并显示错误或日志Tagger.exe中的错误,您将能够检查错误详细信息。

请注意,当您执行某个其他进程的另一个exe时,它将获取进程用户的权限。在处理文件系统等时,权限不足可能会导致问题...


if it running there may be a error when processing files in Tagger.exe, if you can use message box and display error or log the errors in Tagger.exe you will able to check the error details.
note that when you execute, another exe from some other process it will take the privileges of the the process user. insufficient privileges may cause issues when dealing with file system etc...


您写道:这两个文件都存在于POS_Tagger文件夹。好的,但 Tagger.exe 如何找到它们?当然,要提取它自己的位置并使用它来定位文件并不难,但它很可能会在分配给该进程的工作目录中查找。您没有任何工作目录 [ ^ ],默认为空字符串。

试试这个:

You wrote: "Both files are present in POS_Tagger folder". Ok, but how does Tagger.exe find them? Of course, it is not hard to make it extract it's own location and use it to locate files, but it is quite possible, that it will look, in the working directory assigned to the process. You don't assingn any working directory[^], and the default is an empty string.
Try this:
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = @"C:\POS_Tagger\Tagger.exe";
myProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(myProcess.StartInfo.FileName);
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();



加上你可以使用Sysinternal的ProcessMonitor [ ^ ]看看是否有任何事情发生。您还可以跟踪应用程序是否已启动,是否尝试打开某些内容但是失败等等。


Plus you can use Sysinternal's ProcessMonitor[^] to see if anything happens. You can also trace if the applcation is started, if it tries to open something, but fails, and so on.


这篇关于如何在C#中执行exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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