VC++中如何打开一个DOS窗口,然后运行多行命令?注意是多行命令。
比如运行如下命令:cd c:\test
dir
del test.txt注意:希望用户能看到DOS窗口和运行结果。

解决方案 »

  1.   

    还不如写个BAT,然后在VC里面WinExec 调用 cmd.exe 1.bat 不就好了
      

  2.   

    一般情况下都是调用,当然你也可以Winexec运行cmd,然后把批处理一条条传过去,Dos窗口看得到,但运行结果一般都是一闪而过,你不用echo试试
      

  3.   

    函数 system("cd c:\test");
        system("del test.txt");
      

  4.   

    system(cd c:\test );
    system(dir );
    system(del test.txt );
    system(pause);
      

  5.   

    做一个bat文件,内容就是你要执行的命令集,然后执行如下代码:
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    si.dwFlags=STARTF_USESHOWWINDOW;
    si.wShowWindow=SW_SHOW;
    ZeroMemory( &pi, sizeof(pi) );
    //watchdog 
    if( !CreateProcess(NULL,   // No module name (use command line). 
    TEXT("cmd.exe /k xx.bat"), // Command line. 
    NULL,             // Process handle not inheritable. 
    NULL,             // Thread handle not inheritable. 
    FALSE,            // Set handle inheritance to FALSE. 
    0,                // No creation flags. 
    NULL,             // Use parent's environment block. 
    NULL,             // Use parent's starting directory. 
    &si,              // Pointer to STARTUPINFO structure.
    &pi)             // Pointer to PROCESS_INFORMATION structure.

    {
    MessageBox("error");   
    exit(-1);
    }
      

  6.   

    不好意思,上面会打开4个窗口,不能满足要求,下面就可以了    system("cd c:\test & dir & del test.txt & pause"); 
      

  7.   

    在batch最后加个pause命令, 把echo关了就不显示了........
      

  8.   

    //一句话:
    system("cd c:\test&dir&del test.txt&pause" );//VC6.0SP6+XPSP3调试成功!
      

  9.   

    //一句话:
    system("cd c:\test&dir&del test.txt&pause" );//VC6.0SP6+XPSP3调试成功!
      

  10.   

    我调试成功的是VC6system("d: & cd test & dir & del test.txt & pause"); 
      

  11.   

    很抱歉,我刚才可能没把要求将清楚。我希望用户的感觉就像手工执行多条命令一样。所以要满足如下条件:1。不用*.bat文件
    2。不改变命令格式。(不把命令转换为“d: & cd test & dir & del test.txt & pause”)
    3。如果需要的话,用户可以在程序运行完这些命令后,再手工运行一些其他命令。还是要谢谢zngsai和ydfy6,我也会给你们加分的。
      

  12.   

    用System函数或者执行cmd把命令作为参数传过去,可以满足你的1和2条,手工运行的话,还是执行cmd然后传参。
      

  13.   

    怎样把命令传进cmd窗口中呢?
      

  14.   

    做控制台程序,DOS窗口就自动打开了,不用传。CMD也不用了。
      

  15.   

    用SendMessage向CMD的窗口发送字符得了
      

  16.   

    写成bat file就会只有一个窗口打开了