From fea39b5a6b3bb8b4104b6300340dc5c8b5df2bff Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Tue, 12 Mar 2019 00:12:42 +0200 Subject: js: reimplement subprocess using the subprocess command (match 548ef078) Semantics changes are the same as at 548ef078 . Also, the previous C implementation returnd a string for the `stdout` value, but stdout of the subprocess command is MPV_FORMAT_BYTE_ARRAY which js previously didn't support, so support it too (at pushnode) by returning it as a string - the same as the lua code does. --- player/javascript/defaults.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'player/javascript') diff --git a/player/javascript/defaults.js b/player/javascript/defaults.js index cd67a7a2e8..a44e9bb7b2 100644 --- a/player/javascript/defaults.js +++ b/player/javascript/defaults.js @@ -538,6 +538,20 @@ mp.osd_message = function osd_message(text, duration) { mp.commandv("show_text", text, Math.round(1000 * (duration || -1))); } +mp.utils.subprocess = function subprocess(t) { + var cmd = { name: "subprocess", capture_stdout: true }; + var new_names = { cancellable: "playback_only", max_size: "capture_size" }; + for (var k in t) + cmd[new_names[k] || k] = t[k]; + + var rv = mp.command_native(cmd); + if (mp.last_error()) /* typically on missing/incorrect args */ + rv = { error_string: mp.last_error(), status: -1 }; + if (rv.error_string) + rv.error = rv.error_string; + return rv; +} + // ----- dump: like print, but expands objects/arrays recursively ----- function replacer(k, v) { var t = typeof v; -- cgit v1.2.3