Is where a way to use python api in node js?
I want use this api - https://github.com/billy-yoyo/RainbowSixSiege-Python-API for my node js app.
Have you tried running it as terminal commands using:
const {exec} = require('child_process');
exec(scriptToRun, (err, stdout, stderr) => {
if (err) {
// node couldn't execute the command
return;
}
Related
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
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
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 have tried different ways,
i tried shelljs for running these commands for generating CSV from SQLite DB,
shell.exec('sqlite3 /path/to/sqlite-db.db')
shell.exec('.headers on')
shell.exec('.mode csv');
shell.exec('.output /path/to/data.csv');
shell.exec('select * from Table;');
shell.exec('.quit');
but it get stuck on 1st command, i need to run all other commands in SQLite cmd.
On terminal these commands working fine.
Or is there any other way to do that?
You don't need to use the sqlite3 shell, you can pass options instead with Node's built-in child_process.exec()-method.
const exec = require("child_process").exec
const command = 'sqlite3 -header -csv /path/to/sqlite-db.db "select * from Table;" > /path/to/data.csv'
exec(command, (err, stdout, stderr) => {
if (err) return console.error(err)
console.log("stdout: ", stdout)
console.log("stderr: ", stderr)
})
I'm trying to use the Atom electron to write a Desktop App for both Mac and Windows.
What I need here is :
A button.
And when the user click the button it runs the following shell (or python script):
ping x.x.x.x
And the result will be displayed in a TextArea.
I tried to use [shelljs] and [yargs] but it seems like it is not workable with Atom electron.
All I want is to use JAVASCRIPT to write Desktop App (with GUI of course) that calls some script (shell && python) to do some automation work.
Any suggestion will be appreciated, thanks :)
It can be done directly with Node, you can use the child_process module. Please notice this is asynchronous.
const exec = require('child_process').exec;
function execute(command, callback) {
exec(command, (error, stdout, stderr) => {
callback(stdout);
});
};
// call the function
execute('ping -c 4 0.0.0.0', (output) => {
console.log(output);
});
I encourage you to also have a look at npm, there are tons of modules that could help you to do what you want, without calling a python script.
Try node-powershell npm. You can directly execute shell script commands and display result.
var shell = require('node-powershell')
var ps = new shell()
ps.addCommand('ping -c 4 0.0.0.0')
ps.invoke()
.then(function (output) {
console.log(output)
})
.catch(function (err) {
console.log(err)
ps.dispose()
})
See: https://www.npmjs.com/package/node-powershell
you could use child_process to archive what you are trying to do by using the following code
var exec = require('child_process').exec
function Callback(err, stdout, stderr) {
if (err) {
console.log(`exec error: ${err}`);
return;
}else{
console.log(`${stdout}`);
}
}
res = exec('ping xxx.xxx.xxx', Callback);