Rich Cooper wrote:
> I'm trying to pipe a DOS command to a file using a ShellExecute,
> but it doesn't create  the output file.  Here's the code:
> 
> var D : string;
> ...
>   D := GetStartDir;
>   ShellExecute(0,pChar('ipconfig/all > 
> '),pchar('harbor.txt'),nil,pChar(D),SW_SHOWNORMAL);
> ...
> 
> but no file named 'harbor.txt' gets created.  Does anyone know how to
> fix this?

First, "ipconfig/all >" is not a shell verb. Did you read the 
documentation for ShellExecute before composing the code above?

Second, you're telling ShellExecute to look in the registry for the 
"ipconfig/all >" key for files named *.txt, and then execute the command 
it finds there on the harbor.txt file, which I'm guessing doesn't even 
exist.

Third, note that command-line redirection is performed by the 
command-line interpreter. ShellExecute is not a command-line 
interpreter. Read this:

http://blogs.msdn.com/oldnewthing/archive/2006/05/16/598893.aspx

You should be able to find lots of example code to solve your problem 
with the following search:

http://groups.google.com/groups?q=pipe+dos+command&as_ugroup=*delphi*

Fourth, ipconfig is not a DOS command. It's a console program, but it's 
a fully fledged Windows program. Try to run it in DOS (if you even have 
a computer with DOS installed anymore), and you'll simply be told that 
it needs to run in Win32 mode.

Finally, type-casting a string literal to PChar is not necessary and can 
sometimes lead to problems. A string literal can be used as any 
string-related type, including AnsiString, WideString, PAnsiChar, and 
PWideChar. The compiler will choose based on what it needs. You don't 
need to tell it.

-- 
Rob
_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://www.elists.org/mailman/listinfo/delphi

Reply via email to