使用C#程序运行一个可执行程序 [英] using C# Process to run a Executable program
问题描述
我是一个生物信息学的人,我用C#我的工作。我一直使用C#进程运行可执行程序几次。这一次,我有一个新的问题。我下载了Windows中的exe文件的程序命名爆炸(的 http://blast.ncbi.nlm.nih.gov/Blast.cgi?CMD=Web&PAGE_TYPE=BlastDocs&DOC_TYPE=Download )。如果我在键入命令是:
I am a Bioinformatic person and I use C# for my work. I have been using Processes in C# to run Executable programs several times. This time I have a new issue. I have downloaded an exe file in Windows for a program named Blast(http://blast.ncbi.nlm.nih.gov/Blast.cgi?CMD=Web&PAGE_TYPE=BlastDocs&DOC_TYPE=Download). If I type in my command which is :
blastp -query input.txt -db pdbaa -out output.txt
它工作正常。但是,当我将复制一个记事本粘贴命令时,将给出一个错误。我搜索了这个问题,我发现,这是一个编码的问题UTF-8与ISO-拉丁文(的 http://biostar.stackexchange.com/questions/7997/an-error-by-using-ncbi-blast-2-2 -25-上的窗户被复制和粘贴引起)。
it works fine. But when I copy paste the command from a notepad it will give an error. I searched for the problem and I found that it is an "encoding problem UTF-8 versus ISO-latin" (http://biostar.stackexchange.com/questions/7997/an-error-by-using-ncbi-blast-2-2-25-on-windows) which is caused by copy and paste.
现在,我要运行C#中的进程调用的exe文件,我得到了同样的问题,我想这是因为该过程不会像复制和粘贴。这里是我的代码:
Now that I want to run the process from c# to call the exe file I get the same problem and I guess it is because the process does something like copy and paste. Here is my code:
public void Calculate()
{
Process proc = new Process();
proc.StartInfo.WorkingDirectory = Program.NCBIBlastDirectory;
proc.StartInfo.FileName = @"C:\Program Files\NCBI\blast-2.2.25+\bin\blastp.exe";
proc.StartInfo.Arguments = "blastp -query input.txt -db pdbaa -out output.txt";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardError = true;
proc.Start();
proc.WaitForExit();
proc.Close();
}
你有什么想法,我怎么能解决这个问题?
Do you have any idea how I can solve this?
先谢谢了。
推荐答案
有一个问题,我可以看到的是在该行,你设置参数:
One problem I can see is in the line where you set the Arguments:
proc.StartInfo.Arguments = "blastp -query input.txt -db pdbaa -out output.txt";
我觉得你的意思是:
I think you meant:
proc.StartInfo.Arguments = "-query input.txt -db pdbaa -out output.txt";
所以,你不需要在参数再次指定可执行文件的名称 - 这就是filename是
So you don't need to specify the executable name again in the Arguments - that's what FileName is for.
另一件事是,有很多的不表现太清楚,如果你不使用shell-执行启动它们的应用程序。第一次尝试将其与壳执行(显然没有任何重定向性病*),如果它工作的方式,那么你就会知道什么问题是 - 尽管恐怕没有多少你可以做些什么
The other thing is that there are a lot of applications which don't behave too well if you don't use shell-execute to start them. Try it first with shell-execute (and obviously without redirecting any std*), and if it works that way, then you'll know what the issue is - although I'm afraid there's not much you can do about it.
另外,为什么是行
proc.StartInfo.RedirectStandardError = true;
重复两次?
repeated twice?
这篇关于使用C#程序运行一个可执行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!