Run Python script in Bro

Hello all,

I use the str_shell_escape() to run a Python script using command line. I am wondering how I can get the return or print value of Python script, because I will need the result in a if statement in Bro.

Thanks,

Chen Xu

Hi Chen,

I use the str_shell_escape() to run a Python script using command line. I
am wondering how I can get the return or print value of Python script,
because I will need the result in a if statement in Bro.

str_shell_escape() is used to escape strings in that context. I think system() is what you are looking for: https://www.bro.org/sphinx/scripts/base/bif/bro.bif.bro.html#id-system

Jan

The "Exec" library is what you want to use. You can use it like this...

  when ( local ret = Exec::run([$cmd="ls"]) )
    {
    print ret$exit_code;
    print ret$stdout;
    }

The only thing to keep in mind is that the body of "when" statements are only executed once the condition has completed. The body of the when statement will be "registered" and execution will immediately continue below the when statement so you many have to do something like have your if statement you want to do *inside* the when statement's body.

   .Seth