[Bro] Run Python script in Bro

Seth Hall seth at corelight.com
Tue Aug 22 10:55:32 PDT 2017



On 21 Aug 2017, at 16:57, Chen Xu wrote:

> 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.

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



--
Seth Hall * Corelight, Inc * www.corelight.com


More information about the Bro mailing list