Honni
2006-03-23 10:05:28 UTC
I have the following code that takes the Console command line and
passes it to another program. Calling GetCommandLine() function does
not read the "<" for directing the contents of a text file to the
command line.
This does work for redirecting the output to the file.
CString CommandLine = (LPCTSTR) GetCommandLine();
//We need to strip the program name which may be enclosed by ""
if(CommandLine.GetLength() > 0)
{
int nProg;
if(CommandLine[0] == '"')
nProg = CommandLine.Find(_T("\""), 1);
else
nProg = CommandLine.Find(_T(" "), 0);
if(nProg >= 0)
CommandLine = CommandLine.Mid(nProg+1);
}
SHELLEXECUTEINFO ExeInfo;
memset(&ExeInfo,0,sizeof(SHELLEXECUTEINFO));
ExeInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ExeInfo.fMask = SEE_MASK_NOCLOSEPROCESS |
SEE_MASK_NO_CONSOLE;
ExeInfo.nShow = SW_SHOW;
ExeInfo.lpVerb = "open";
ExeInfo.lpFile = "t:\\ss\\win32\\sse.exe";
ExeInfo.lpParameters = CommandLine;
if(ShellExecuteEx(&ExeInfo))
{
(void)WaitForSingleObject (ExeInfo.hProcess, INFINITE);
(void)GetExitCodeProcess(ExeInfo.hProcess,&ExitCode);
(void)CloseHandle (ExeInfo.hProcess);
}
else
AfxMessageBox(_T("Error : t:\\ss\\win32\\sse.exe failed to
execute"));
passes it to another program. Calling GetCommandLine() function does
not read the "<" for directing the contents of a text file to the
command line.
This does work for redirecting the output to the file.
CString CommandLine = (LPCTSTR) GetCommandLine();
//We need to strip the program name which may be enclosed by ""
if(CommandLine.GetLength() > 0)
{
int nProg;
if(CommandLine[0] == '"')
nProg = CommandLine.Find(_T("\""), 1);
else
nProg = CommandLine.Find(_T(" "), 0);
if(nProg >= 0)
CommandLine = CommandLine.Mid(nProg+1);
}
SHELLEXECUTEINFO ExeInfo;
memset(&ExeInfo,0,sizeof(SHELLEXECUTEINFO));
ExeInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ExeInfo.fMask = SEE_MASK_NOCLOSEPROCESS |
SEE_MASK_NO_CONSOLE;
ExeInfo.nShow = SW_SHOW;
ExeInfo.lpVerb = "open";
ExeInfo.lpFile = "t:\\ss\\win32\\sse.exe";
ExeInfo.lpParameters = CommandLine;
if(ShellExecuteEx(&ExeInfo))
{
(void)WaitForSingleObject (ExeInfo.hProcess, INFINITE);
(void)GetExitCodeProcess(ExeInfo.hProcess,&ExitCode);
(void)CloseHandle (ExeInfo.hProcess);
}
else
AfxMessageBox(_T("Error : t:\\ss\\win32\\sse.exe failed to
execute"));