Hi,

I have a output redirect problem in NAnt.

I defined a custom NAnt task. Inside it, I have the following code:

           TextWriter standardOut = Console.Out;
           TextWriter standerdError = Console.Error;
           int exitValue;
           using (TextWriter newOutWriter = File.CreateText(output),
                               newErrorWriter = newOutWriter)
           {
               Console.SetOut (newOutWriter);
               Console.SetError(newErrorWriter);
               exitValue = ExternalProgram.ExecuteProgram(command,
                                                                arguments);
           }
           Console.SetOut(standardOut);
           Console.SetError(standerdError);

Basicly, it will execute an external program then redirect that program's
output to a file of which the name is stored in the variable - output. The
ExecuteProgram method is defined as below.

   public class ExternalProgram
   {
       public static int ExecuteProgram(string program, string arguments)
       {
           Process process = new Process();
           process.StartInfo.FileName = program;
           process.StartInfo.Arguments = arguments;
           process.StartInfo.UseShellExecute = false;
           process.StartInfo.RedirectStandardOutput = true;
           process.StartInfo.RedirectStandardError = true;
           process.StartInfo.CreateNoWindow = true;
           process.Start();

           process.WaitForExit();

           return process.ExitCode ;
       }
   }

Put the above code outside NAnt task, they work as expected. The output is
redirected to a file. But using the above code in NAnt custom task, nothing
is redirected to the file. Could someone tell me the reason and give me a
solution? Thank you in advance.
 
Best regards,

Yuncong
 
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to