ShellExecuteEx path question. [modified] (fixed)
-
Edit : Issue was mostly with the spawned EXE that did not handled parameters properly. Now everything is working ok. Thanks. I'm trying to figure out a couple of issues I have with some path that contains spaces when using
ShellExecuteEx
: The current directory contains space :C:\Users\me\Documents\Visual Studio 2008\Projects\asdcasd\asdcasd
TCHAR Buffer\[MAX\_PATH\]; DWORD dwRet; dwRet = GetCurrentDirectory(MAX\_PATH, Buffer); // wrap the path with quotes CString sWorkingPath; sWorkingPath.Format( \_T("\\"%s\\""), Buffer ); CString command ( \_T("XMLtoPDF.exe")); CString parameters( \_T("")); // /noopen // wrap the path with quotes. CString sExe; sExe.Format ( \_T("\\"%s\\\\%s\\""), Buffer, command); SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE\_MASK\_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = \_T("open"); ShExecInfo.lpFile = sExe; ShExecInfo.lpParameters = parameters; ShExecInfo.lpDirectory = sWorkingPath; ShExecInfo.nShow = SW\_SHOW; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
The exe spawns a console (it's a perl byte-compiled stand-alone) and tells me the path is not good :
C:\Users\me\Documents\Visual
does not exists. I've checked the path and they all semms to be double-quoted to handle the spaces. Am i missing something ? Thanks a bunch.Watched code never compiles.
modified on Thursday, July 8, 2010 3:52 PM
-
Edit : Issue was mostly with the spawned EXE that did not handled parameters properly. Now everything is working ok. Thanks. I'm trying to figure out a couple of issues I have with some path that contains spaces when using
ShellExecuteEx
: The current directory contains space :C:\Users\me\Documents\Visual Studio 2008\Projects\asdcasd\asdcasd
TCHAR Buffer\[MAX\_PATH\]; DWORD dwRet; dwRet = GetCurrentDirectory(MAX\_PATH, Buffer); // wrap the path with quotes CString sWorkingPath; sWorkingPath.Format( \_T("\\"%s\\""), Buffer ); CString command ( \_T("XMLtoPDF.exe")); CString parameters( \_T("")); // /noopen // wrap the path with quotes. CString sExe; sExe.Format ( \_T("\\"%s\\\\%s\\""), Buffer, command); SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE\_MASK\_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = \_T("open"); ShExecInfo.lpFile = sExe; ShExecInfo.lpParameters = parameters; ShExecInfo.lpDirectory = sWorkingPath; ShExecInfo.nShow = SW\_SHOW; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
The exe spawns a console (it's a perl byte-compiled stand-alone) and tells me the path is not good :
C:\Users\me\Documents\Visual
does not exists. I've checked the path and they all semms to be double-quoted to handle the spaces. Am i missing something ? Thanks a bunch.Watched code never compiles.
modified on Thursday, July 8, 2010 3:52 PM
Suggestions: 1) Use
GetShortPathName()
. 2) UseUrlEscape()
. I'm not sure if either will work, however."One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius