命令行下用重定向是可以的.不要用system()哦,它会产生一个黑框框.大家帮忙啊!!!

解决方案 »

  1.   

    在命令行下敲a.exe > list.txt当然是可以了,但如何在程序中实现呢?
    _execl("a.exe", "a.exe", ">list.txt", NULL);
    不管用啊. 大家帮忙哈!
      

  2.   

    如果这个Console程序是自己写的话,就自己在程序中用CFile类或CStdioFile自己把输出结果写入指定文本文件。
      

  3.   

    用CreateProcess创建的时候可以制定stdin/stdout/stderr的句柄,然后……
      

  4.   

    #include <iostream.h>
    #include <afx.h>void main()
    {
    CStdioFile file;
    CString str="\n这是我要添加在最后面的一行。";
    file.Open("f:\\text.txt",CStdioFile::modeReadWrite);
    file.SeekToEnd();
    file.WriteString((LPCSTR)str);  //自己打开这个文件查看一下,呵呵,偷个懒
    file.Close();
    }
      

  5.   

    试试
      GetStdHandle
      ReadConsoleOutput
    函数吧
      

  6.   

    研究了一下,原来是如此简单!#include <io.h>
    #include <stdio.h>
    #include <process.h>int main()
    {
    FILE* fp=fopen("list.txt", "w");
    _dup2(_fileno(fp),1);
    _spawnl(_P_WAIT, "hello.exe", "hello.exe", NULL);
    fclose(fp);
    return 0;
    }//hello.c, produce hello.exe
    #include <stdio.h>int main()
    {
    printf("Hello,world!\n");
    return 0;
    }
      

  7.   

    用CreateProcess把输出管道重定向到文件,这样输入就到文件了。创建的时候,加入SW_HIDE选项,这样就不会出现控制台窗口。
      

  8.   

    _dup2还是不行,会弹出CONSOLE框,真是郁闷!
      

  9.   

    http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=185751这个问题我前天还在做呢,经过1个星期的寻找,我找到了,是用window  管道技术来做的。  
     
    void  CDosWindowsDlg::OnButton1()    
    {  
               //  TODO:  Add  your  control  notification  handler  code  here  
     SECURITY_ATTRIBUTES  sa;  
     HANDLE  hRead,hWrite;  
     
     sa.nLength  =  sizeof(SECURITY_ATTRIBUTES);  
     sa.lpSecurityDescriptor  =  NULL;  
     sa.bInheritHandle  =  TRUE;  
     if  (!CreatePipe(&hRead,&hWrite,&sa,0))  {  
               MessageBox("Error  On  CreatePipe()");  
           return;  
     }    
     
     STARTUPINFO  si;  
     PROCESS_INFORMATION  pi;    
     si.cb  =  sizeof(STARTUPINFO);  
     GetStartupInfo(&si);    
     si.hStdError  =  hWrite;  
     si.hStdOutput  =  hWrite;  
     si.wShowWindow  =  SW_HIDE;  
     si.dwFlags  =  STARTF_USESHOWWINDOW    &brvbar;  STARTF_USESTDHANDLES;  
     if  (!CreateProcess(NULL,"cmd.exe  /c  dir  /?"  
                 ,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))  {  
                 MessageBox("Error  on  CreateProcess()");  
                 return;  
     }  
     CloseHandle(hWrite);  
     
     char  buffer[4096]  =  {0};  
     DWORD  bytesRead;    
     while  (true)  {  
             if  (ReadFile(hRead,buffer,4095,&bytesRead,NULL)  ==  NULL)  
                     break;  
             m_Edit1  +=  buffer;//m_Edit1是CString  
             UpdateData(false);  
             Sleep(200);    
     }    
    }  
     
      

  10.   

    谢谢vcmute(横秋)!我试试看行不行
      

  11.   

    vcmute(横秋)的方法可以!谢谢!!