Search code examples
delphidelphi-xe8

running multiple commands in cmd with Delphi


I am trying to use cmd from Delphi to apply some commands. I use following code

ShellExecute(Application.handle, 'runas', 'cmd.exe',
  PChar('/c command to do '), nil, SW_show);

I want to run more than one command in the same execution, for example

/c command1 command2 command3

I already made a bat file to run some commands. But I don't like the idea of storing a bat to my project. Can I apply more than one command in one execution? Can this be done?


Solution

  • You can try separating commands with &&, here is working example

      ShellExecute(Application.handle, 'open', 'cmd.exe',
        PChar('/c "copy /Y file1.txt file2.txt&&copy /Y file2.txt file3.txt"'), nil, SW_show);