Last active
August 29, 2015 14:06
-
-
Save Noitidart/16cd799f6bbfbcdea12f to your computer and use it in GitHub Desktop.
_ff-addon-snippet-X11_bash - Trying to run bash with ps on X11 system to get list of running process IDs and names.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var thisWin = Services.ww.activeWindow; | |
var env = Cc['@mozilla.org/process/environment;1'].getService(Ci.nsIEnvironment); | |
var pathFor = { | |
'ps': 0, | |
'bash': 0 | |
}; | |
var fileFor = {}; //populatdd based on pathsFor | |
var paths = env.get('PATH').split(':'); | |
var len = paths.length; | |
for (var p in pathsFor) { | |
for (var i = 0; i < len; i++) { | |
try { | |
var fullyQualified = new FileUtils.File(OS.Path.join(paths[i], p)); | |
console.log('search for:', p, 'fullyQualified:', fullyQualified.path) | |
if (fullyQualified.exists()) { | |
fileFor[p] = fullyQualified; | |
pathFor[p] = fullyQualified.path; | |
break; | |
} | |
} catch (e) { | |
// keep checking PATH if we run into NS_ERROR_FILE_UNRECOGNIZED_PATH | |
} | |
} | |
} | |
if (!fileFor.bash || !fileFor.ps) { | |
console.error("Error: a task list executable not found on filesystem"); | |
thisWin.alert('Error: a task list executable not found on filesystem'); | |
throw new Error("Error: a task list executable not found on filesystem"); | |
} | |
var procFinned = { | |
observe: function (aSubject, aTopic, aData) { | |
thisWin.alert('ps completed'); | |
} | |
}; | |
var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess); | |
var pathOutput = OS.Path.join(OS.Constants.Path.desktopDir, 'newt.txt'); | |
var args = ['-c', pathFor.ps.replace(/\W/g, '\\$&') + ' aux > ' + pathOutput.replace(/\W/g, '\\$&')]; | |
process.init(fileFor.bash); | |
process.runAsync(args, args.length, procFinned); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
README
Rev1
Rev2
args
was preventing it from workingRev3
replace
s on the file paths in the arguments as per https://github.com/mozilla/build-partner-repacks/blob/9f1515011674ba8e7f3e9b1fd409c426d5104765/partners/yandex-drp/distribution/extensions/yasearch%40yandex.ru/cbapp/parts/integration.js#L184