命令窗口

Posted pond-zzc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了命令窗口相关的知识,希望对你有一定的参考价值。

void CFileRenameDlg::_execute(const CString& cmd)
{
SECURITY_ATTRIBUTES sa;
HANDLE hRead,hWrite;

sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;

if(!CreatePipe(&hRead,&hWrite,&sa,0))
{
MessageBox(_T("启动失败"));
return;
}

STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory(&si,sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.hStdError = hWrite;
si.hStdOutput = hWrite;
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;

CString sCmd = _T("cmd /c "") + cmd + _T(""");
TCHAR* szCmd = new TCHAR[sCmd.GetLength() + 1];
_tcscpy(szCmd, sCmd.GetString());

if(!CreateProcess(NULL, szCmd, NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))
{
MessageBox(_T("启动失败"));
delete[] szCmd;
return;
}
delete[] szCmd;
CloseHandle(hWrite);

char buffer[4096] = {0};
CString strOutput;
DWORD bytesRead;

while(1)
{
if(NULL == ReadFile(hRead,buffer,4095,&bytesRead,NULL))
{
break;
}
strOutput += buffer;
Sleep(1000);
}
CloseHandle(hRead);
}

 

test:

_execute(_T("D:\test.csv"));

以上是关于命令窗口的主要内容,如果未能解决你的问题,请参考以下文章

linux怎么用命令打开命令窗口

pl/sql里面命令窗口和sql窗口区别是啥?

如何对命令提示符窗口中的字体进行修改

易语言如何向CMD窗口发送命令?

Q语言 我的命令库《通用》窗口命令功能函数源码

powershell快捷方式里添加命令,执行完命令后会关闭窗口,怎么能在执行完命令后不让窗口关闭