我尝试通过delphi在shell中执行命令,但它不起作用。 我使用这个脚本:
var
shellexecommand:string;
begin
ShellExecute(0, nil, 'cmd.exe', '/C ' + shellexecommand + ' > output.txt', nil, SW_HIDE);
end;
但我收到错误:
[dcc32 Error] Unit1.pas(329): E2010 Incompatible types: 'PWideChar' and 'AnsiString'
此外,如果我将字符串更改为 pwidechar 也是行不通的。 我该如何解决这个问题?
最佳答案
试试这个:
var
shellexecommand:string;
begin
// shellexecommand := ....
shellexecommand := '/C ' + shellexecommand + ' > output.txt';
ShellExecute(0, nil, 'cmd.exe', PChar(shellexecommand), nil, SW_HIDE);
end;
关于delphi - 如何使用变量运行 shellexecute?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22166005/