Apply #1157 by @mluds as patch (fix #1158, #1026)
Encoding and other fixes for #1157

Log as one statement. No need to hold the filesystem lock. New variable name.
No shell execution (#1157)

Now that we do the proper thing, we do not need shell parsing.
Changelog for #1026, #1157, #1158