added exec(cmd,output,input,error,avpenv) function for exec

Seems redundant to re-set outval.flags and rs.s every iteration (and rs.len for that matter).

Shouldn't you move everything from outval.flags to the end of this block to outside the `while{}`?