Executing external application

Anyone know how to do this in Delphi ?

Suppose I have a command line application C:\Tools\CheckFiles.exe

I need to execute it from my Delphi application and get the result in a text file.

In MSDOS prompt I can do it like this: C:\Tools\CheckFiles.exe > LOG.txt

Thanks
dudupAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dudupAuthor Commented:
It does not work :(

The application is not a DOS application, it has some DLLs also.

0
dudupAuthor Commented:
This is work, but I cant redirect output and hide the dos prompt.

function TForm1.ExecuteAndWait(const CommandLine : string) : cardinal;
var
 tSI : TStartupInfo;
 tPI : TProcessInformation;
 dwI : DWORD;
 VarU : UINT;
begin
 Result := ErrUINT;
 FillChar(tSI, sizeof(TStartupInfo), 0);
 tSI.cb := sizeof(TStartupInfo);

 if (CreateProcess(nil, pchar(CommandLine), nil, nil, False, 0, nil, nil, tSI, tPI)) then begin
   dwI := WaitForSingleObject(tPI.hProcess, INFINITE);

   if (dwI = WAIT_OBJECT_0) then
     if (GetExitCodeProcess(tPI.hProcess, dwI)) then Result := dwI;

   CloseHandle(tPI.hProcess);
   CloseHandle(tPI.hThread);
 end;
end;
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

DragonSlayerCommented:
In that case, try something simpler?

WinExec(PChar('C:\Tools\CheckFiles.exe > LOG.txt'), SW_HIDE);
0
dudupAuthor Commented:
The problem is, even in a dos prompt, I cant capture the output using ">"

The program that I want to execute is "cdrdao" http://www.cdrdao.org

I tried to do "cdrdao.exe scanbus > log"

But it does not work.
0
dudupAuthor Commented:
0
DragonSlayerCommented:
Well, use that method and save the string buffer to a file then ;-)
0
TiborKiCommented:
That solves evrything:

http://www.torry.net/samples/samples/soft/console.zip

I use it by my own applications, and it's the best!


0
TiborKiCommented:
And a sample for console.zip:


function TForm1.GetText: string;
var OutPut, Params: TStringList;
     Exename: String;
begin
Params:=TStringList.Create;
Exename:='C:\Test.exe';
Output:=TStringList.Create;
ExecConsoleApp(Exename, Params.Text, Output, nil);
Result:=Output.Text;
Output.Free;
Params.Free;
end;
0
TiborKiCommented:
Choose me. :-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dudupAuthor Commented:
You are choosen my "son" ..... j/k :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.