Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am on 64 bit windows 7 (locale is US English)
i have a .bat file whose name is in russian characters. This is inside a folder and again folder name is in Russian .
Now using C++, i want to execute that batch file . What all do in need to do ?
I understand that using wide char strings will help but i found on net that wide char is not same as UNICODE. What will be a good approach here ?
following code works
C++
if( !CreateProcessW( L"E:\\TestFolder\\test.bat",// L"E:\\TestFolder\\процессов.bat";
                                                 //does not work
    NULL,NULL,NULL,
    FALSE,
    0,NULL,NULL,
    &si, &pi )
)
{
    printf( "CreateProcess failed (%d).\n", GetLastError() );
    return 0;
}
Posted

use unicode
http://msdn.microsoft.com/en-US/goglobal/cc305144[^]

nd if needed it's nasty conversion routines
http://msdn.microsoft.com/en-us/library/windows/desktop/dd318026(v=vs.85).aspx

Your project can stay english but use the API-functions ending with "W" for processing the unicode strings.
 
Share this answer
 
v2
Comments
chandanadhikari 18-Feb-14 7:53am    
thanks for your help. The first link says '... requested page can not be found..."
KarstenK 18-Feb-14 8:04am    
corrected :-)
According to the CreateProcess()[^] function in the MSDN, batch files require special handling:
Quote:
To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file.
When using the lpCommandLine parameter with the Unicode version, it must be a non const pointer (see the above link).

So you may try this:
C++
wchar_t lpszCmdLine[] = L"/c E:\\TestFolder\\процессов.bat";
if( !CreateProcessW( 
    L"cmd.exe",
    lpszCmdLine,NULL,NULL,
    FALSE,
    0,NULL,NULL,
    &si, &pi )
)
 
Share this answer
 
Comments
Jochen Arndt 18-Feb-14 8:21am    
No!

The TEXT() and _T() macros depend on the Unicode setting of the build. When Unicode is not defined, they pass the content as is. When Unicode is defined, the content is prefixed with 'L'.

When explicitly calling a W or A API function or assigning text to a char / wchar_t variable, the matching text must be passed. When using a non Unicode build and passing a TEXT() or _T() string to a W function or wchar_t variable, the compiler will generate a C2664 type conversion error.
KarstenK 18-Feb-14 8:31am    
You are right - I will delete my comment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900