我在阅读一个GUI程序时,发现程序中夹杂着许多Console.WriteLine()
似乎是作者用于输出软件运行信息的。我如何能够得到这些输出信息呢?
程序为C#写的

解决方案 »

  1.   

    Visual Studio debug程序的时候
    输出里边会有Console.WriteLine()输出的内容。
      

  2.   

    项目上右键 属性Output type 改为 Console Application
      

  3.   

    一个调用Win32 API的类
    [DllImport("Kernel32.dll")]
            private static extern bool AllocConsole(); //启动窗口
            [DllImport("kernel32.dll", EntryPoint = "FreeConsole")]
            private static extern bool FreeConsole();      //释放窗口,即关闭
            [DllImport("user32.dll", EntryPoint = "FindWindow")]
            extern static IntPtr FindWindow(string lpClassName, string lpWindowName);//找出运行的窗口
            [DllImport("user32.dll", EntryPoint = "GetSystemMenu")]
            extern static IntPtr GetSystemMenu(IntPtr hWnd, IntPtr bRevert); //取出窗口运行的菜单
            [DllImport("user32.dll", EntryPoint = "RemoveMenu")]
            extern static IntPtr RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags); //灰掉按钮调用方法如下
                AllocConsole();
                IntPtr windowHandle = FindWindow(null, Process.GetCurrentProcess().MainModule.FileName);
                IntPtr closeMenu = GetSystemMenu(windowHandle, IntPtr.Zero);
                uint SC_CLOSE = 0xF060;
                RemoveMenu(closeMenu, SC_CLOSE, 0x0);
                for(int i=0;i<100;i++)
                {
                    Console.WriteLine("i=:" + i);               
                }
      

  4.   


    编译后,点exe运行后,会有一个命令窗口弹出来
      

  5.   

    原始GUI程序我没法编译 
    因此 能不能不修改原EXE程序
      

  6.   

    你可以使用Process启动这个程序,然后重定向输出
    StartInfo.RedirectStandardError
    StartInfo.RedirectStandardOutput
    详细的你可以搜索一下重定向输出