One nice thing about this setup is that it's not specific to Clojure/Lisp; any scripting language with a REPL will do this well:<p><i>Python:</i><p><pre><code> import subprocess
import json
def osquery(query):
return json.loads(subprocess.check_output(["osqueryi", "--json", query]))
#>>> osquery("select * from routes where destination = '::1'")
#>>> [{'destination': '::1', 'flags': '2098181', 'gateway': '::1', 'hopcount': '0', 'interface': 'lo0', 'metric': '0', 'mtu': '16384', 'netmask': '128', 'source': '', 'type': 'local'}]
</code></pre>
<i>Node:</i><p><pre><code> const { execFile } = require("child_process");
async function osquery(query) {
return new Promise((resolve, reject) => {
execFile("osqueryi", ["--json", query], (error, out, _err) => {
if (error) {
reject(error);
return;
}
resolve(JSON.parse(out));
});
});
}
//> await osquery("select * from routes where destination = '::1'");
//> [
//> {
//> destination: '::1',
//> flags: '2098181',
//> gateway: '::1',
//> hopcount: '0',
//> interface: 'lo0',
//> metric: '0',
//> mtu: '16384',
//> netmask: '128',
//> source: '',
//> type: 'local'
//> }
//> ]
</code></pre>
<i>Ruby:</i><p><pre><code> require "open3"
require "json"
def osquery(query)
out, err, exit_status = Open3.capture3("osqueryi", "--json", query)
if exit_status != 0
raise err
end
return JSON.parse(out, symbolize_names: true)
end
#irb(main):1:0> osquery("select * from routes where destination = '::1'")
#=>
#[{:destination=>"::1",
# :flags=>"2098181",
# :gateway=>"::1",
# :hopcount=>"0",
# :interface=>"lo0",
# :metric=>"0",
# :mtu=>"16384",
# :netmask=>"128",
# :source=>"",
# :type=>"local"}]</code></pre>