# print statement redirection

**URL:** <https://community.zeek.org/t/print-statement-redirection/3418>\
**Category:** Zeek\
**Created:** [January 8, 2015, 2:26pm UTC](https://community.zeek.org/t/print-statement-redirection/3418 "2015-01-08T14:26:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Donnelly](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@John\_Donnelly](https://community.zeek.org/u/John_Donnelly)\
**Post date:** [January 8, 2015, 2:26pm UTC](https://community.zeek.org/t/print-statement-redirection/3418/1 "2015-01-08T14:26:48Z")

</div>

Hi,  
I am trying to locate how the “print” and “print fmt” statements work in bro scripts ; where are they implemented in source ? Specifically I am trying to determine if they always use stdout and stderr as inherited by src/main.cc

Any suggestions welcome !

---

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [January 8, 2015, 2:39pm UTC](https://community.zeek.org/t/print-statement-redirection/3418/2 "2015-01-08T14:39:09Z")

</div>

Is this sort of what you’re looking for?

global my\_file = open(“test.txt”);  
event bro\_init()  
&nbsp;&nbsp;{  
&nbsp;&nbsp;print my\_file, “woo!”;  
&nbsp;&nbsp;}

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![John\_Donnelly](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@John\_Donnelly](https://community.zeek.org/u/John_Donnelly)\
**Post date:** [January 8, 2015, 2:47pm UTC](https://community.zeek.org/t/print-statement-redirection/3418/3 "2015-01-08T14:47:51Z")

</div>

That is interesting , but it doesn’t really satisfy my curiosity Does the scripting I/O not use stderr + stdout ? I am interested in getting bro to redirect to syslog by inheriting file descriptors on startup .

---

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [January 8, 2015, 3:03pm UTC](https://community.zeek.org/t/print-statement-redirection/3418/4 "2015-01-08T15:03:37Z")

</div>

Ah, ok. I didn’t understand where you are trying to get to in the end. It does use stdout if you don’t send the content off to a certain location. I take it that you have a script you’ve written that prints? I’m asking since Bro doesn’t print much to stdout or stderr by default I don’t immediately see the utility of redirecting those to syslog.  
  
The implementation for the print statement can be found in Stmt.cc around line 259.

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [January 8, 2015, 3:27pm UTC](https://community.zeek.org/t/print-statement-redirection/3418/5 "2015-01-08T15:27:46Z")

</div>

> That is interesting , but it doesn't really satisfy my curiosity Does the  
> scripting I/O not use stderr + stdout ?

By default, print does go to stdout. The code is in src/Stmt.cc,  
PrintStmt::DoExec().

> I am interested in getting bro to redirect to syslog by inheriting  
> file descriptors on startup .

Just to be sure, you know there's a builtin function syslog(msg),  
right?

Robin

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:42pm UTC](https://community.zeek.org/t/print-statement-redirection/3418/6 "2022-05-06T15:42:20Z")

</div>


