Answer the question
In order to leave comments, you need to log in
WinAPI: ShellExecute. Passing launch options to an application?
Good evening (morning/afternoon/night). I am writing a program using WinAPI. In particular, the ShellExecute function . This program calls a console application, passes parameters to it (outputting the STDERR stream to a text file).
On the command line I write like this: program.exe -2>err.txt
In the program code I write like this:
ShellExecute(handle, 'open', 'program.exe', '-2>err.txt', nil, SW_SHOW);
Answer the question
In order to leave comments, you need to log in
I/O redirection is NOT a command line option.
Try experimenting with CreateProcess, the lpStartupInfo parameter might be helpful.
Try this:
ShellExecute(handle, 'open', 'cmd.exe', '/C program.exe > err.txt', nil, SW_SHOW);
Exactly as the previous speaker said.
Open the file via CreateFile with SECURITY_ATTRIBUTES.bInheritHandle = TRUE and do CreateProcess with bInheritHandles = TRUE and lpStartupInfo.dwFlags |= STARTF_USESTDHANDLES , lpStartupInfo.hStdError = hFile .
> ShellExecute(handle, 'program.exe', '-2>err.txt', nil, SW_SHOW);
One more argument is missing between handle and 'program.exe'.
Maybe use WinExec instead of ShellExecute?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question