DOS external commands like xcopy not working in a batch file started from CreateProcess API

66 views
Skip to first unread message

Dodo Sturm

unread,
Dec 15, 2010, 6:37:22 AM12/15/10
to
Hi,

I'm using CreateProcess API to launch a batch file. Here are the
parameters I'm using:
CreateProcessW( NULL, // application name, is in 99.99% cases NULL
L"c:\\Windows\\system32\\cmd.exe /C \"c:\\temp\\myBatchFile.bat
\" "
NULL, // process security attributes
NULL, // thread security attributes
true, // inherit the handles
CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT |
NORMAL_PRIORITY_CLASS, // creation flags
lpEnv, // environment variables
L"C:\\temp", // working directory
&si,
&pi );

Everything works OK, the batch file is executed and the commands in
the batch file are correctly executed. The si.hStdOutput is used and
the output redirection works correctly.
The only problem are the DOS external commands like xcopy or find:
they are not working withing the batch file.
E.g. when I use this batch file

c:\Windows\system32\find.exe "foo" "c:\temp\bar.txt"
echo %ERRORLEVEL%

at the end the %ERRORLEVEL% is 1 and find.exe does not return
anything.
If I run the batch file directly from a DOS window the find.exe is
working correctly.

Any ideas?

Thanks for your help
Dorel Sturm

Reply all
Reply to author
Forward
0 new messages