How to use Delphi to execute a .bat file properly

23.4k Views Asked by At

I am running a .bat file from delphi(2010).

procedure TForm1.Button2Click(Sender: TObject);
var sCmd: String;
 Begin
sCmd := Pwidechar('b4a_c2dm.bat' +' ' +'send ' + Trim(Edit1.Text)+' '  + Trim(edit2.Text ));
ShellExecute(0, 'open', 'b4a_c2dm.bat', PChar(sCmd), nil, SW_SHOWMAXIMIZED);
   end;

This opens the cmd.exe and passes the correct string in the cmd.exe , BUT

Some how the line in the .bat file (java -cp b4a_c2dm.jar anywheresoftware.b4a.c2dm.C2DM %*) is showing up in the cmd.exe window and not letting the .bat file do its job.

Can someone help me with this.

1

There are 1 best solutions below

5
No'am Newman On BEST ANSWER

In order to execute a batch file, the program to be called is 'cmd' and its parameter should be the name of the batch file.

Regarding your program,

ShellExecute (application.handle, 'open', 'cmd', PChar(sCmd), nil, SW_MAXIMIZE)