I need to execute a Windows "find" command from a Delphi software. I've tried to use the ShellExecute
command, but it doesn't seem to work. In C, I'd use the system
procedure, but here... I don't know. I'd like to do something like this:
System('find "320" in.txt > out.txt');
Edit : Thanks for the answer :) I was trying to run 'Find' as an executable, not as argument for cmd.exe.
An example using
ShellExecute()
:Note that using
CreateProcess()
instead ofShellExecute()
allows for much better control of the process.Ideally you would also call this in a secondary thread, and call
WaitForSingleObject()
on the process handle to wait for the process to complete. TheSleep()
in the example is just a hack to wait some time for the program started byShellExecute()
to finish -ShellExecute()
will not do that. If it did you couldn't for example simply open anotepad
instance for editing a file,ShellExecute()
would block your parent app until the editor was closed.Variant1:
This will run a 'DOS' program and retrieve its output:
Variant 2:
Capture console output in [Realtime] and how it in a TMemo:
Source: delphi.wikia.com