Link to home
Start Free TrialLog in
Avatar of mdavis1982
mdavis1982

asked on

Executing DOS commands

Hi!

How can I execute a DOS command in Delphi, and get the results from it put into a memo?

ie. I want to execute a DIR command with some switches, and have the output from the DIR put into a memo.  Also, I will need to use the rename command, although if I can get the file name from the DIR, then I can do this programmatically in Delphi!

I'm using Delphi 6 Enterprise...  Thanks for your help...

mdavis1982
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

There are several ways.

1 - You could try using ShellExecute to run the command CMD.EXE or COMAMND.COM with the paramater of "/cDIR directory > LOG.TXT"

2 - You could create a batch file containing all the code you want WITH the redirection to a text file already done and then ShellExecute that batch file.

Once you've got the output file, you can load it into your memo.

3 - You could use something like the code that is available at ...

http://www.delphifreestuff.com/examples/redir.html

This code still stores the output into a file, but you could probably modify it to feed your memo instead.

I don't know if this code is D6 compatible, but it is a start point maybe.

Regards,

Richard Quadling.
Avatar of craig_capel
craig_capel

When someone has given you all the information you need to complete your task, look at thier comment box and in the top right you will see "accept comment as answer" click on it when you feel they have answered your question. the other time is when the user selects thier comment as answer, however this does not happen often because it's polite to let the user decide if it helped them or not.

-

Craig C.
ASKER CERTIFIED SOLUTION
Avatar of Rabster
Rabster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mdavis1982

ASKER

Thanks! That's great!  Oh, and here's 20 extra points for answering my question! #:o)

Matt