?
Solved

Executing external application

Posted on 2004-11-19
12
Medium Priority
?
221 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:dudup
  • 5
  • 3
  • 3
11 Comments
 

Author Comment

by:dudup
ID: 12623394
It does not work :(

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

0
 

Author Comment

by:dudup
ID: 12623662
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:DragonSlayer
ID: 12623840
In that case, try something simpler?

WinExec(PChar('C:\Tools\CheckFiles.exe > LOG.txt'), SW_HIDE);
0
 

Author Comment

by:dudup
ID: 12624749
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
 

Author Comment

by:dudup
ID: 12625326
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 12628161
Well, use that method and save the string buffer to a file then ;-)
0
 
LVL 1

Expert Comment

by:TiborKi
ID: 13026253
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
 
LVL 1

Expert Comment

by:TiborKi
ID: 13026299
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
 
LVL 1

Accepted Solution

by:
TiborKi earned 660 total points
ID: 13381727
Choose me. :-)
0
 

Author Comment

by:dudup
ID: 13437298
You are choosen my "son" ..... j/k :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question