2

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.

2
  • If you've copied and pasted your arguments from notepad too, then they probably have kept the encoding. Save the text file with ansi encoding in notepade, then copy these arguments. Commented Nov 11, 2011 at 13:19
  • 1
    Are you sure you should have "blastp" as the first word in the arguments? Is that not the exe name? The process would now call this command: C:\Program Files\NCBI\blast-2.2.25+\bin\blastp.exe blastp -query input.txt -db pdbaa -out output.txt Commented Nov 11, 2011 at 13:24

1 Answer 1

4

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Yes The problem was in the Arguments statment. I remove dthe blastp and is working now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.