I have an application which needs to run with the following command:
be-engine.exe -u producer -c D:\Workspace\V114_new\KinesisChannel\kinesis.cdd D:\Workspace\V114_new\KinesisChannel.ear -n logs002
Here i need to navigate to the bin director of the installed application and the run the be-engine.exe passing other file paths as well in the command on windows.
I want to automate this using protractor so that on start the above commands run automatically and engine gets started.
Is there a way to do this in protractor using javascript.
NodeJS has exec method for this:
const { exec } = require('child_process');
exec('be-engine.exe -u producer -c D:\Workspace\V114_new\KinesisChannel\kinesis.cdd D:\Workspace\V114_new\KinesisChannel.ear -n logs002', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.error(`stderr: ${stderr}`);
});
https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
Check also this answer: Execute a command line binary with Node.js
Related
Hello I have got a jar file lavalink to be exact which is basically a music module now i would like to start the jar file from my index.js(Main bot file) as I am not in the financial state to pay for a separate host for the lavalink server and would like to start and use the lavalink server in the same hosting container
No I am not running it in a browser I am using discord.js wrapper to interact with the discord API to make a backend program
Installation
Install child process npm i child-process this allows you to execute shell comands
Command
give the exec function as first parameter your command
exec("cd ~/<path-to-directory-jarFile> && java -jar Myjar_file.jar
cd ~/<path-to-directory-jarFile> goes in the directory where your jar file is
java -jar Myjar_file.jar executes your jar file
the && executes your commands consecutevely first the one before then the one after
Example
const { exec } = require("child_process");
exec("cd ~/<path-to-directory-jarFile> && java -jar Myjar_file.jar ", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
Executing Shell Commands in NodeJS:
https://stackabuse.com/executing-shell-commands-with-node-js/
Hello I am looking to try and send commands to a program through node js. I am using child processes to exec the jar file. I have trouble sending the commands however
const exec = require('child_process').exec;
exec('java -jar C:\\Users\\19144\\Desktop\\all\\amp1\\Ampera1.jar -full', (e, stdout, stderr) => {
if (e instanceof Error) {
console.error(e);
throw e;
}
console.log('stdout ', stdout);
console.log('stderr ', stderr);
});
This is the child process being spawn and I wish to send the following command to the jar
'sendTransaction 12500000skms5OGjlKm5NJ7fyftdxkma9kUFR3ZxUO4EFw==GgpH9KkC 100 Ampera'
is there any way to feasible do this
12500000skms5OGjlKm5NJ7fyftdxkma9kUFR3ZxUO4EFw==GgpH9KkC
and
100
are variables
In the middle of my Node.js file I want to store the terminal response of docker run -v ${PWD}/app.py:/app.py proj1part1dockerimage in my file and store the output as a var. How would i go about getting a terminal response without opening a terminal?
In node.js everything is asynchronous, so you have to use a callback:
child_process.exec("docker run -v ${PWD}/app.py:/app.py proj1part1dockerimage",
(err, stdout, stderr) => {
const output = stdout.toString();
}
)
But if you require it to be instant which I don't recommend:
const output = child_process.execSync("docker run -v ${PWD}/app.py:/app.py proj1part1dockerimage").toString();
I am trying to execute a bunch of bash commands using node.js. I used child_process.exec to execute the commands.
var child_process = require('child_process');
child_process.exec("ps -p $(lsof -ti tcp:8088) o pid=,comm=",function(err,stdout, stderr){
if(err){
console.log('error',err);
return;
}
console.log('stdout', stdout);
});
This will list the process id running in the port 8088 along with name. In the similar way when i try to execute top command with a process id to check cpu and memory utilization. I am facing an error.
var execTop = function(pid){
child_process.exec("top -p 12769", function(err, stdout, stderr){
if(err){
console.log('error',err);
return;
}
console.log("top output",stdout);
})
}
I couldn't find much resource online to clarify this issue. The actual error is
error { [Error: Command failed: /bin/sh -c top -p 12769
top: failed tty get
]
killed: false,
code: 1,
signal: null,
cmd: '/bin/sh -c top -p 12769' }
I appreciate the possible solutions suggested. Thanks in advance.
If you really want to run top like this, you need to run in it "Batch Mode", like:
top -b -n 1 -p 12345
This is because top is usually meant to be an interactive command and wants to have an actual terminal to write to. You might want to consider using something like ps u -p 12345 for more concise output.
as Grisha suggested, use the 'Batch Mode' and if only cpu and memory is needed, for default top output I'd use something like:
top -b -n 1 -p 12345 | awk '{if(NR>7)print $9,$10}'
Is there any way to run shell command from JavaScript in node-webkit?
There is a lot of similar questions, but it didn't help me.
I'm trying to build simple desktop app for listing installed tools.
I've created node module 'tools-v' which is installed globally and works when I run it in command line.
This module run several commands: npm -v, node -v, git -v etc.
I'm on Windows 7.
//var sys = require('sys');
var exec = require('child_process').exec;
//var toolsv = (process.platform === "win32" ? "tools-v.cmd" : "tools-v");
$(document).ready(function() {
//myCmd = "C:\\Users\\win7\\AppData\\Roaming\\npm\\tools-v.cmd";
//myCmd = toolsv;
myCmd = 'tools-v';
//gui.Shell.openItem('firefox',function(error, stdout, stderr) { });
//opening Firefox works.
exec(myCmd, function (error, stdout, stderr) {
//detached: true;
console.log('stdout: ' + stdout);
$('#output').append('stdout: ' + stdout)
if (error !== null) {
console.log('exec error: ' + error);
}
});
});
I'm always getting error:
""exec error: Error: spawn ENOENT""
I tried spawn instead of exec. I also tried several other commands, beside node module.
Thanks.
Actually, this code works. I just didn't built full app, I tested it trough sublime build for node-webkit. Preforming full build with grunt solved every spawn issues.