A
A
agul2011-02-05 16:58:28
Windows
agul, 2011-02-05 16:58:28

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);

Without parameters ('-2>err.txt') the program starts and displays errors in the console. And with the parameters it also outputs to the console, although it needs to be in a file.
Where is the mistake? How can you do better?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
al_one, 2011-02-05
@al_one

I/O redirection is NOT a command line option.
Try experimenting with CreateProcess, the lpStartupInfo parameter might be helpful.

D
Demon2, 2011-02-05
@Demon2

Try this:
ShellExecute(handle, 'open', 'cmd.exe', '/C program.exe > err.txt', nil, SW_SHOW);

Y
yeputons, 2011-02-05
@yeputons

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 .

Y
yopopt, 2011-02-05
@yopopt

> 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?

X
xRay, 2011-02-05
@xRay

Here we already fought with such a question: http://www.wasm.ru/forum/viewtopic.php?id=8962

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question