using C# Process to run a Executable program
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";
So you don't need to specify the executable name again in the Arguments - that's what FileName is for.
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.
Also, why is the line
proc.StartInfo.RedirectStandardError = true;
repeated twice?
Reyhaneh
Updated on June 04, 2022Comments
-
Reyhaneh almost 2 years
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
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.
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?
Thanks in advance.