gpt4 book ai didi

ada - 你如何在 Ada 中调用外部程序?

转载 作者:行者123 更新时间:2023-12-02 19:23:49 25 4
gpt4 key购买 nike

如何从 Ada 程序文本中调用外部命令(就像我在 Unix shell 或 Windows 命令提示符下输入的一样)?

我更喜欢非特定于 gnat 的解决方案,但无论如何我都会发布我自己发现的内容作为初始答案。

最佳答案

你也可以使用system。支持例如

请注意,错误会写入标准错误。

ma​​in.adb

with Ada.Text_IO;
with Interfaces.C;

procedure Main is

package C renames Interfaces.C;
use type C.int;

function system (command : C.char_array) return C.int
with Import, Convention => C;

command : aliased constant C.char_array :=
C.To_C ("mv README.md README.txt");

result : C.int;

begin
result := system (command);
if result = 0 then
Ada.Text_IO.Put_Line ("OK");
else
Ada.Text_IO.Put_Line ("Failed");
end if;
end Main;

关于ada - 你如何在 Ada 中调用外部程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62658196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com