strerrno(errno) 与终端不 return 相同的消息

strerrno(errno) doesn't return the same message with terminal

当我打印执行一个不存在的命令如“asdf”的错误信息时:

execl("/bin/asdf", "asdf", NULL);
printf("%s\n", strerror(errno));

我收到消息 No such file or directory。另一方面,如果我 运行 在终端中执行相同的命令,我会得到

Command 'asdf' not found, did you mean:

  command 'sdf' from deb sdf (2.001+1-7)
  command 'asdfg' from deb aoeui (1.7+20160302.git4e5dee9-2)
  command 'adsf' from deb ruby-adsf (1.4.3+dfsg1-1)
  command 'sadf' from deb sysstat (12.2.0-2ubuntu0.1)

Try: sudo apt install <deb name>

由于我正在构建一个伪终端,有没有办法在 Unix 中重新创建实际终端发送的消息?提前致谢!

根据@Gerhardh 的建议,运行 您通过 shell:

命令
execl("/bin/bash", "bash", "-c", "asdf", "/bin/asdf");

is there a way to recreate the message send by the actual terminal in Unix?

简而言之伪代码:

execl("/bin/asdf", "asdf", NULL);
if (errno == command does not exists) {
    if (fork() == 0) {
        execl("/usr/lib/command-not-found", "/bin/asdf", NULL);
    }
    wait();
}

见末尾 /etc/bash.bashrc - 处理程序在那里。