aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2023-10-02 10:21:56 +0530
committersinanmohd <sinan@sinanmohd.com>2023-10-02 10:21:56 +0530
commit83ab1b000a92286e4c033653f25c6ca270393bcc (patch)
tree3327425cf1beda5cae0a30c95a088a2ea222ede6 /lib
parent93fab4b3e185a95497cb789047518aa428f0abd5 (diff)
lib/util: init run
Diffstat (limited to 'lib')
-rw-r--r--lib/util.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/util.lua b/lib/util.lua
index f3632f2..8ea7699 100644
--- a/lib/util.lua
+++ b/lib/util.lua
@@ -122,6 +122,40 @@ local opensubtitles_hash = function (fileName)
return string.format("%08x%08x", hi,lo), size
end
+local table_to_cmd = function (t)
+ local str = ""
+
+ for _, v in ipairs(t) do
+ v = v:gsub("'", "\'")
+ str = str .. " '" .. v .. "' "
+ end
+
+ return str
+end
+
+local run = function (args)
+ local sig, rc, stdout, cmd
+
+ if mp then
+ cmd = mp.command_native({
+ name = 'subprocess',
+ capture_stdout = true,
+ args = args,
+ })
+ stdout = cmd.stdout
+ rc = (cmd.status >= 0)
+ else
+ cmd = io.popen(table_to_cmd(args))
+ if cmd then
+ stdout = cmd:read('*all')
+ _, sig, rc = cmd:close()
+ rc = (sig == 'signal') or (sig == 'exit' and rc == 0)
+ end
+ end
+
+ return stdout, rc
+end
+
return {
table_merge = table_merge,
table_print = table_print,
@@ -129,5 +163,6 @@ return {
zip_ext_first = zip_ext_first,
string_vid_path_to_name = string_vid_path_to_name,
opensubtitles_hash = opensubtitles_hash,
+ run = run,
error = error,
}