2
votes

I try to execute a command in shell via delphi but it won't work. I use this script:

var
shellexecommand:string;
begin
ShellExecute(0, nil, 'cmd.exe', '/C ' + shellexecommand + ' > output.txt', nil, SW_HIDE);
end;

But i get the error:

[dcc32 Error] Unit1.pas(329): E2010 Incompatible types: 'PWideChar' and 'AnsiString'

Also if i change string to pwidechar is doesn't work. How can i fix this?

1
You might be better with CreateProcess here. Particularly if you actually want the output of the other process in the parent and don't need the text file to endure.David Heffernan

1 Answers

5
votes

Try this:

var
  shellexecommand:string;
begin
  // shellexecommand := ....
  shellexecommand := '/C ' + shellexecommand + ' > output.txt';
  ShellExecute(0, nil, 'cmd.exe', PChar(shellexecommand), nil, SW_HIDE);
end;