using C# Process to run a Executable program
-
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.
-
Answer:
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 at Stack Overflow Visit the source
Related Q & A:
- How to Set Specific Site Collection as SharePoint Search Scope using C#?Best solution by SharePoint
- How to run a external program in PHP?Best solution by Stack Overflow
- Is it possible to develop iPhone application using C#?Best solution by Stack Overflow
- How to programatically select a item in list using c#?Best solution by Software Quality Assurance & Testing
- How do I connect to SQL Server using C#?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.