在 S-Lang 中,可以使用 system()
函数来执行 shell 命令。
cmd = "dir";
status = system(cmd);
if (status != 0) {
printf("Command failed with exit code %d\n", status);
}
这个示例定义了一个 cmd
变量,用于存储要执行的命令字符串 "dir"
。
然后使用 system()
函数调用操作系统中的 shell,并在其中执行给定的命令字符串。cmd
变量作为参数传递给 system()
函数,表示要执行的命令。
system()
函数返回命令执行后的状态码。如果状态码不为 0,则表示命令执行失败,此时输出错误信息和退出码。