Add Zotero.Utilities.Internal.subprocess(command, args)
To run a short-lived command and return stdout The Subprocess module can also start long-running process and communicate with them, but we'll implement something different for that if we need it.
This commit is contained in:
parent
522de4ad92
commit
478dcc4f0f
1 changed files with 31 additions and 1 deletions
|
@ -26,6 +26,12 @@
|
|||
***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
var { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(globalThis, {
|
||||
Subprocess: "resource://gre/modules/Subprocess.jsm",
|
||||
});
|
||||
|
||||
/**
|
||||
* @class Utility functions not made available to translators
|
||||
*/
|
||||
|
@ -619,6 +625,30 @@ Zotero.Utilities.Internal = {
|
|||
return deferred.promise;
|
||||
}),
|
||||
|
||||
/**
|
||||
* Run a short-lived process and return its stdout
|
||||
*
|
||||
* @param {String} command - The command to run; if no slashes, will search PATH for the command
|
||||
* @param {String[]} args - An array of arguments to pass to the command
|
||||
* @return {String}
|
||||
*/
|
||||
subprocess: async function (command, args) {
|
||||
command = command.includes('/') ? command : await Subprocess.pathSearch(command);
|
||||
|
||||
Zotero.debug("Running " + command + " " + args.map(arg => "'" + arg + "'").join(" "));
|
||||
|
||||
let proc = await Subprocess.call({
|
||||
command,
|
||||
arguments: args,
|
||||
});
|
||||
let result = "";
|
||||
let str;
|
||||
while ((str = await proc.stdout.readString())) {
|
||||
result += str;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get string data from the clipboard
|
||||
* @param {String[]} mimeType MIME type of data to get
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue