I am creating an add-on for Mozilla.
I have seen that if I know the path of a file, I can execute it by spawning the process.
But is it possible to execute system commands like "ls", "dir", "javac" etc. from my mozilla add-on directly?
Thanks in advance.
Edit:
I have found a way to run .bat and .sh file in windows and Linux through my Mozilla Add-on using javascript. But is there a way to run .sh file in Mac?
Below I have mentioned some code to show how I am doing that for Linux.
var exefile = Components.classes["#mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
/**
* Path to terminal file.
* I need same for Mac.
*/
exefile.initWithPath("/usr/bin/gnome-terminal");
var run = Components.classes['#mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
run.init(exefile);
var parameters = ["-e", path_of_shell_script]; //with arguments
run.run(false, parameters,parameters.length);
I am not into these kind of concepts. But the question is a bit intriguing. So, i peeped into it.
Well If you can call the file then you can call an batch file or shell script which will do the trick for you.
Related
I have a JavaScript code that I need to run on chrome console. I can upload it and run it on Chrome, but I'm trying to automate that by writing a Python script that does the same. Here is what the python script should do:
1) Take in input from the user, using Command Line arguments in python. e.g.:
python FileName.py --from www.abc.com --to www.def.com
2) Update 2 variables in said DoSomething.JS as:
var from_site = "www.abc.com"
var to_site = "www.def.com"
3) Upload the JS file to chrome and run it in console.
4) The JS file does its job and downloads something. Parse the data through python (I can do this) and run some other commands in said chrome console, all through the same script.
Is there a library I can look up in order to do this? I'm trying to run the python script locally on my laptop.
Using windows my code I currently use:
var file = JSON.parse(fs.readFileSync(filePath), 'utf8');
file[id] = JSON.parse(`{"name":name}`);
fs.writeFileSync(filePath, JSON.stringify(file,null,2);
This works just fine on windows. However, when I transfer this code onto my linux machine for cross-platform testing. The file doesn't get updated until I stop running the application.
What i've tried:
running 'chmod -r 0777 path/to/dir/'
and
checked if it was due to max file open limit (not the case as my limit is extremely large)
Linux: Mint-Linux 4.10.0-38-generic #42~16.04.1-Ubuntu (from uname -a)
Node: 8.10.0
Editor: intelliJ idea
Im also running the code directly from the run button in intelliJ, im not sure if this may be the cause, if it is the cause why would this be the case.
Adding the option {mode: 0o777} as the last arg in the write fixed the files not updating.
I know Windows 8 'apps' can be developed using web technologies but I haven't been able to find out if terminal commands can be run in the background using web technologies as an interface. I basically have mongoDB on my computer and it takes two terminal windows open to run it. I thought it might be a neat project to see if I could write a little app that is nothing more than a button that launches both commands behind the scenes saving me the hassle of going to the directories and running the commands manually for both terminal windows.
If you plan to launch apps via server-side JavaScript (e.g. node.js), use the child_process module..
The workflow would be that in the windows 8 gui side, it will just issue a request to your own local server in node.js, then it would execute those commands.
Example:
var exec = require('child_process').exec;
var child = exec("insert command here", function(err, stdout, stderr) { });
See examples exec and spawn for more examples.
======
Another thing you can do is create a batch (.bat) file that contains those two commands needed for your mongodb instance and put that as a shortcut in the Windows 8 Start Screen.
It depends on what kinds of commands you need to execute, and when and where. If you plan to execute commands remotely, I'd assume server-side JS would be appropriate, but if you plan to execute commands locally, I think all you need is just batch scripting.
I got a js file to do something automatically.
But the default program in my PC to run js file is Word.
There seems to be no available program in my open with.. list
How can I run this type of file?
You can try using these options. open the CMD (or Command Prompt) and type this
Cscript.exe "FileName.js"
or
Wscript.exe "FileName.js"
More info? Read the Microsoft
Documentation
You can use Open with --> Microsoft Windows Based Script Host if available or browse to cscript.exe or wscript.exe in System 32 folder manually whereas cscript.exe is used for console applications and wscript.exe for windows applications.
Anyone here have experience using Selenium and webdriverjs? I'm coming from a non-Java background with a good deal of experience with Node.js and JavaScript in general. According to the Selenium docs, you have to set-up a stand-alone Selenium server to use the node web driver. Fortunately, they seem to be bundled together.
npm install webdriverjs
gets you the JAR file for the standalone selenium server inside the node_modules/webdriverjs/bin directory. Example tests are inside the node node_modules/webdriverjs/examples directory but the tests in them fail when I run them from either the webdriverjs or examples directories.
What's the missing piece here? What's the quickest way to get up and running?
I have read the docs.
Note: Stack overflow wouldn't let me use the tag webdriverjs, but this is specifically about webdriverjs, not using selenium with Java or other languages.
Update: The only problem was that the built-in example tests are broken!
Here's what I did to get webdriverjs working:
Step 1: start selenium standalone in my laptop by running command java -jar selenium-server-standalone-2.33.0.jar. then it will listen to http://localhost:4444/ and you can access it via http://localhost:4444/wd/hub/. You also need to make sure Firefox browser is installed on your laptop.
Step 2: create a new directory and run command npm install webdriverjs.
Step 3: create a new file named test_webdriverjs.js in the new directory you created, and it looks like this:
var webdriverjs = require('webdriverjs');
var client = webdriverjs.remote({
host: 'localhost',
port: 4444
});
client.init();
client.url('https://github.com/')
.getTitle(function(err, title) { console.log (title)}).call(function () {});
client.end();
Then run command node test_webdriverjs.js under the same directory and you will find it works. If it doesn't work, paste out the console output.