hide the console window while using system(...)
-
chandu004 wrote:
STARTUPINFO s; s.wShowWindow=STARTF_USESHOWWINDOW&&SW_SHOW ;
s.dwFlags = STARTF_USESHOWWINDOW;
s.wShowWindow = SW_SHOW;«_Superman_» I love work. It gives me something to do between weekends.
no difference still iam using it this way.
STARTUPINFO s; s.dwFlags=STARTF\_USESHOWWINDOW; s.wShowWindow=SW\_SHOW ; int ret=CreateProcess(str,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&s,NULL);
here, str contains the command to be executed. which is working perfectly when i use it with system(). what is the mistake here?
-
no difference still iam using it this way.
STARTUPINFO s; s.dwFlags=STARTF\_USESHOWWINDOW; s.wShowWindow=SW\_SHOW ; int ret=CreateProcess(str,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&s,NULL);
here, str contains the command to be executed. which is working perfectly when i use it with system(). what is the mistake here?
Try this.
STARTUPINFO si;
PROCESS_INFORMATION pi;::SecureZeroMemory(&si, sizeof(STARTUPINFO));
::SecureZeroMemory(&pi, sizeof(PROCESS_INFORMATION));si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;::CreateProcess(NULL, str, NULL, NULL, NULL, NULL, NULL, NULL, &si, &pi);
«_Superman_» I love work. It gives me something to do between weekends.
-
Try this.
STARTUPINFO si;
PROCESS_INFORMATION pi;::SecureZeroMemory(&si, sizeof(STARTUPINFO));
::SecureZeroMemory(&pi, sizeof(PROCESS_INFORMATION));si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;::CreateProcess(NULL, str, NULL, NULL, NULL, NULL, NULL, NULL, &si, &pi);
«_Superman_» I love work. It gives me something to do between weekends.
securezeromemory undeclared identifier. this is how the vc++6.0 bangs me. though i included winbase.h. here i will try to simplify my problem. say,
str="dir >>c:\\output.txt";
now i want this command to be executed . can we work in this direction?
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
-
securezeromemory undeclared identifier. this is how the vc++6.0 bangs me. though i included winbase.h. here i will try to simplify my problem. say,
str="dir >>c:\\output.txt";
now i want this command to be executed . can we work in this direction?
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
Use
memset
instead.«_Superman_» I love work. It gives me something to do between weekends.
-
Rajesh R Subramanian wrote:
So, you are not working with any DOS commands.
no the sequence of command which i was talking about may also have them. Yes, i tried to use the create process. but..
CString str; str.Format("copy database\\\\\*.\* %s>>c:\\\\output.txt",tempfolder); DeleteFile("output.txt"); STARTUPINFO s; s.wShowWindow=STARTF\_USESHOWWINDOW&&SW\_SHOW ; int ret=CreateProcess(str.GetBuffer(str.GetLength()),NULL,NULL,NULL,NULL,NULL,NULL,NULL,&s,NULL); //system(str);
there is no result. what is the mistake here.
chandu004 wrote:
what is the mistake here.
The "mistake" is that you are not using
SHFileOperation()
to copy the folder contents."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
chandu004 wrote:
what is the mistake here.
The "mistake" is that you are not using
SHFileOperation()
to copy the folder contents."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
thanks for your reply. can you pleaase explain me how and where to use this function? thanks in advance.
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
-
thanks for your reply. can you pleaase explain me how and where to use this function? thanks in advance.
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
chandu004 wrote:
can you pleaase explain me how and where to use this function?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
hai all, in one of my applications, i have to automate a dos level command. so i construct the command into an str and execute it using system(str). but in this case, the console window is getting flashed while the command is being executed. could any one suggest any other alternative to avoid the display of console. thanks in advance.
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
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
-
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
-
chandu004 wrote:
actually, there are some Third party command mode tools which should be used in a sequence to perform some operations on wav files and text ifles.
So, you are not working with any DOS commands. Like the other poster suggested, you can use
CreateProcess
to hide the window that the new process will spawn. There are ways to capture and process output from a console window: Creating a child process with Redirected input and output[^] Redirecting an arbitrary Console's Input/Output[^] Writing to and read from the console - From a GUI application using the same cout/cin and printf/scanf[^] Generally, you need not use thesystem()
command. It has several disadvantages over the APIs and can affect the performance of your program, for what it's worth. Consider usingCreateProcess
,ShellExecute
, or a similar API function instead.It is a crappy thing, but it's life -^ Carlo Pallini
Rajesh R Subramanian wrote:
Redirecting an arbitrary Console's Input/Output[^]
dear rajesh, this seems to be a perfect source match for my type of requirement. today iam planning to integrate this feature into my app. but i found it in vs 2008. i have to use it in vc 6.0. i will try it and come here if iam facing any problems. many more thanks again.
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.