Link to home
Start Free TrialLog in
Avatar of helyonprime96
helyonprime96

asked on

delphi : how to execute a cmd command?

hello huys.
please help.
how i can execute a cmd command from delphi app? (look like rasdial)

it maybe something like this :
exec ('rasdial life);

Thanks.
Avatar of brezniczky
brezniczky
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,

A very simple way is to simply call ShellExecute with passing the DOS command in as a parameter. E.g. to create a copy of c:\1.txt as c:\2.txt we can use the following:

  ShellExecute(
    Application.Handle, 'open', 'cmd.exe',
    '/c copy c:\1.txt c:\2.txt', // this way we told cmd.exe to execute copy ...
    nil, SW_SHOWNORMAL);

Should you need to wait for the outcome (exit code), a better solution would be using the CreateProcess API.

But in case you need the output (stdout) things can get complicated. Do you?
ASKER CERTIFIED SOLUTION
Avatar of brezniczky
brezniczky
Flag of United Kingdom of Great Britain and Northern Ireland image

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 helyonprime96
helyonprime96

ASKER

ok.thanks.i will test
thanks