其中流不"砸检测的QUOT栈;消息得到打印到? [英] Which stream does "stack smashing detected" message get printed to?

查看:153
本文介绍了其中流不"砸检测的QUOT栈;消息得到打印到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面非常基本的程序,它曾出现在许多形式的其他问题在这里。

Consider the following very basic program, which has appeared in many forms on other questions here.

#include <string.h>

int main() {
    char message[8];
    strcpy(message, "Hello, world!");
}

在我的系统,如果我把这个在一个名为 Classic.c ,没有任何特殊标志编译并运行它,我得到以下输出。

On my system, if I put this in a file called Classic.c, compile it with no special flags and run it, I get the following output.

$ gcc -o Classic Class.c 
$ ./Classic
*** stack smashing detected ***: ./Classic terminated
Aborted (core dumped)

通常情况下,节目输出到标准错误标准输出,所以我预计下会产生没有输出。

Normally, program output goes to stderr or stdout, so I expected that the following would produce no output.

./Classic  2> /dev/null > /dev/null

但是,输出是完全一样的,所以我有三个问题,这种情况下。

However, the output is exactly the same, so I have three questions to this scenario.


  1. 正在打印什么流在这里?

  2. 我怎么能写code打印到这个特殊的流(无需刻意砸我的筹码)。

  3. 如何重定向此流的输出?

请注意,我在Linux系统上运行。具体而言,Ubuntu的14.04。

Note I am running on a Linux system. Specifically, Ubuntu 14.04.

推荐答案

因为它不是标准错误或标准输出,只有一个剩下的选择:控制tty

Since it's not stderr or stdout, there's only one remaining option: The controlling tty.

您可以通过打开的/ dev / tty的写这个与code。

You can write to this with your code by opening /dev/tty.

重定向输出是故意非常困难的(这就是为什么的/ dev / tty的也用于密码提示)。这就是说,如果你真的想这样做,期望可用于这一目的,正如

Redirecting its output is intentionally very difficult (this is why /dev/tty is also used for password prompts). That said, if you really want to do it, expect can be used for this purpose, as can emPTY.

最容易的方法期待是使用附带的帮手无缓冲,这将有效地重定向这些内容到标准输出

The easiest approach with expect is to use the included helper unbuffer, which will effectively redirect this content to stdout:

$ sh -c 'echo hello >/dev/tty' >/dev/null 2>&1
hello
$ unbuffer sh -c 'echo hello >/dev/tty' >/dev/null 2>&1
$

这篇关于其中流不&QUOT;砸检测的QUOT栈;消息得到打印到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆