我想使用Delphi(7)的DOS命令显示目录的内容。使用Win10 - 64
以下程序显示DOS shell但不显示目录内容。我的代码出了什么问题?
SELECT
CONCAT(
REPLACE(
LEFT('07970000007',2), '07', '+447'
),
SUBSTRING('07970000007', 3, CHAR_LENGTH('07970000007'))
)as replaced
答案 0 :(得分:5)
在Windows 10上运行代码会返回2,即ERROR_FILE_NOT_FOUND
。
我通过将其更改为32位和64位目标平台来实现它 这样:
var
ComSpec: string;
retval: HINSTANCE;
begin
ComSpec := GetEnvironmentVariable('comspec');
retval := ShellExecute(Handle, nil, PChar(comspec), '/k dir', nil, SW_SHOW);
if retval <= 32 then
Caption := Format('Error, return value = %d', [retval])
else
Caption := 'Success';
end;
/k
表示要运行cmd.exe
的新实例并保持窗口打开。有关更多详细信息,请从命令提示符运行cmd /?
。
请注意ShellExecute
的错误处理非常有限。如果您希望全面检查错误,则必须使用ShellExecuteEx
。