64,647
社区成员
发帖
与我相关
我的任务
分享
// testconsole.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
//在winexec之前进行打印操作
printf("Usage: xxxxxxxxxxxxxx\n");
//获取执行文件所在的路径
char drive[_MAX_DRIVE];
char Execpath[MAX_PATH];
{
char dir[_MAX_DIR];
_splitpath( argv[0], drive, dir, NULL, NULL);
_makepath( Execpath, drive, dir, NULL, NULL );
}
//启动新cmd,并进入该路径
std::string cmd = "cmd.exe /k \"";
cmd += drive;
cmd += "&&cd ";
cmd += Execpath;
cmd += "\"";
WinExec(cmd.c_str(),SW_SHOW);
//如果在winexec之后进行打印操作,很可能打印的东西出现在新cmd提示符之后,而且光标停顿在
//信息之后,并等待按键
//Sleep(1000); //这里是模拟打印的执行在winexec执行成功之后,
//printf("Usage: xxxxxxxxxxxxxx\n"); //
return 0;
}
该帖变为送分贴,保留两三天