Click here to Skip to main content
15,895,011 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: hide the console window while using system(...) Pin
chandu00429-Jun-09 3:47
chandu00429-Jun-09 3:47 
GeneralRe: hide the console window while using system(...) Pin
David Crow29-Jun-09 4:14
David Crow29-Jun-09 4:14 
GeneralRe: hide the console window while using system(...) Pin
chandu00430-Jun-09 21:41
chandu00430-Jun-09 21:41 
AnswerRe: hide the console window while using system(...) Pin
«_Superman_»29-Jun-09 1:44
professional«_Superman_»29-Jun-09 1:44 
GeneralRe: hide the console window while using system(...) Pin
chandu00429-Jun-09 1:51
chandu00429-Jun-09 1:51 
GeneralRe: hide the console window while using system(...) Pin
chandu00429-Jun-09 2:31
chandu00429-Jun-09 2:31 
GeneralRe: hide the console window while using system(...) Pin
«_Superman_»29-Jun-09 2:33
professional«_Superman_»29-Jun-09 2:33 
AnswerRe: hide the console window while using system(...) [modified] Pin
Joe Woodbury29-Jun-09 12:00
professionalJoe Woodbury29-Jun-09 12:00 
I often use ShellExecuteEx (look it up to know what libraries to link.) This wraps CreateProcess in an easier to use form. I've cut and paste a modified version here.)

To execute a copy; pass "cmd.exe" as the app and "/c command" as the args. Set pDir to the dir where you want the operation to take place. Pass false for show. (The /c tells cmd.exe to execute the command and then exit.)

bool Execute(LPCTSTR pApp, LPCTSTR pArgs, bool show, LPCTSTR pDir)
{
	if (!pApp)
	{
		SetLastError(ERROR_FILE_NOT_FOUND);
		return false;
	}

	SHELLEXECUTEINFO execInfo;
	memset(&execInfo, 0, sizeof(execInfo));

	execInfo.cbSize       = sizeof(execInfo);
	execInfo.fMask        = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
	execInfo.lpFile       = pApp;
	execInfo.lpParameters = pArgs;
	execInfo.nShow        = show ? SW_SHOW : SW_HIDE;

	char path[MAX_PATH];

	if (pDir)
	{
		execInfo.lpDirectory = pDir;
	}
	else
	{
		lstrcpyn(path, pApp, MAX_PATH);
		if (PathRemoveFileSpec(path))
		{
			if (path[0])
				execInfo.lpDirectory = path;
		}
	}

// DTDirExits is an internal function that uses GetFileAttributes() to test if a path is an existing directory
	if (execInfo.lpDirectory && !DTDirExists(execInfo.lpDirectory))
	{
		SetLastError(ERROR_PATH_NOT_FOUND);
		return false;
	}

	if (!ShellExecuteEx(&execInfo))
		return false;

	if (execInfo.hProcess)
		CloseHandle(execInfo.hProcess);

	return true;
}


modified on Tuesday, August 4, 2009 11:15 AM

GeneralRe: hide the console window while using system(...) Pin
chandu00430-Jun-09 1:27
chandu00430-Jun-09 1:27 
QuestionQuerry. Pin
Razanust29-Jun-09 0:49
Razanust29-Jun-09 0:49 
AnswerRe: Querry. Pin
chandu00429-Jun-09 0:57
chandu00429-Jun-09 0:57 
AnswerRe: Querry. Pin
«_Superman_»29-Jun-09 0:57
professional«_Superman_»29-Jun-09 0:57 
GeneralRe: Querry. Pin
Rajesh R Subramanian29-Jun-09 1:28
professionalRajesh R Subramanian29-Jun-09 1:28 
GeneralRe: Querry. [modified] Pin
chandu00429-Jun-09 1:34
chandu00429-Jun-09 1:34 
AnswerRe: Querry. Pin
Rajesh R Subramanian29-Jun-09 1:03
professionalRajesh R Subramanian29-Jun-09 1:03 
QuestionApplication freeze Pin
susanne129-Jun-09 0:27
susanne129-Jun-09 0:27 
QuestionRe: Application freeze Pin
«_Superman_»29-Jun-09 0:32
professional«_Superman_»29-Jun-09 0:32 
AnswerRe: Application freeze Pin
susanne129-Jun-09 0:36
susanne129-Jun-09 0:36 
AnswerRe: Application freeze Pin
Rajesh R Subramanian29-Jun-09 0:38
professionalRajesh R Subramanian29-Jun-09 0:38 
GeneralRe: Application freeze Pin
susanne129-Jun-09 0:52
susanne129-Jun-09 0:52 
GeneralRe: Application freeze Pin
Rajesh R Subramanian29-Jun-09 0:58
professionalRajesh R Subramanian29-Jun-09 0:58 
GeneralRe: Application freeze Pin
susanne129-Jun-09 1:45
susanne129-Jun-09 1:45 
GeneralRe: Application freeze Pin
Rajesh R Subramanian29-Jun-09 1:52
professionalRajesh R Subramanian29-Jun-09 1:52 
AnswerRe: Application freeze Pin
Michael Thärigen12-Sep-09 22:54
Michael Thärigen12-Sep-09 22:54 
Questiontimer start problem Pin
susanne129-Jun-09 0:25
susanne129-Jun-09 0:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.