Running an executable file from a remote machine on my local machine using node.js

As we develop our application using node.js and electron, we encounter a situation where another software is already installed on all other machines. Now, the question arises: Can we launch this software from within our node.js application on these respective machines?

Answer №1

If you want to execute commands using a child process in Node.js, you can achieve this through the spawn method. For more information, refer to the NodeJs API Docs

Executing Commands on Windows

const { spawn } = require('child_process');
const bat = spawn('cmd.exe', ['/c', 'my.bat']);

bat.stdout.on('data', (data) => {
  console.log(data.toString());
});

bat.stderr.on('data', (data) => {
  console.log(data.toString());
});

bat.on('exit', (code) => {
  console.log(`Child exited with code ${code}`);
});

Executing Commands on Linux

const { spawn } = require('child_process');
const ls = spawn('ls', ['-lh', '/usr']);

ls.stdout.on('data', (data) => {
  console.log(`stdout: ${data}`);
});

ls.stderr.on('data', (data) => {
  console.log(`stderr: ${data}`);
});

ls.on('close', (code) => {
  console.log(`child process exited with code ${code}`);
});

Answer №2

I had great success with the following code:

const exec = require('child_process').exec;
exec('WMIC /node:"XYZ-ABCDEFG" process call create "D:\\Program\\program.exe"', (error, stdout, stderr) => {
    console.log('error:', error);
    console.log('stderr:', stderr);
});

Remote computer name: XYZ-ABCDEFG

Executable file path on remote computer: D:\Program\program.exe

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting: Vue.js file upload encountering OPTIONS 404 error

In my express app, I have configured CORS and most of the routes are working fine. However, I'm facing an issue with a specific component used for uploading images: <input type="file" class="form-control" @change="imageChanged"> <div @clic ...

Utilizing React with file system and path dependent packages

Is there a way to utilize the quick.db package in my ReactAPP with hooks, even though React does not allow the use of FS & Path which are required for this package? I am encountering the following errors: ERROR in ./node_modules/file-uri-to-path/index.js ...

In the event of a 404 error, simply direct the user to the pageNotFound before ultimately guiding them back

I'm developing a website with Node JS and I want to implement a feature where if the user attempts to navigate to a non-existent page, they are redirected to a "Page Not Found" message before being automatically taken back to the home page after a few ...

What is the most straightforward method for saving sessions in Connect that is working right now?

I've been searching for session store implementations compatible with Connect in node.js, but haven't had much luck. While Connect-Redis is effective, the dependency on Redis is something I'd prefer to avoid. Sesame/nStore seemed promising, ...

difficulty in obtaining information submitted through a form

I'm having an issue with my contact form. I tried testing to see if I can retrieve the values from the form, but it's giving me back: name: undefined I'm not sure why it's not working! Here is the code for the form: <form met ...

Is it possible to add more data to additional fields in a mongoose document after it has already been loaded?

After loading a document, I want to populate additional fields. In the ecommerce application I'm building, I load my cart on all routes using the following code: app.use(function(req, res, next) { Cart.findOne({session: req.cookies['express:s ...

The response from MongoDB may either be null or indicate that a specific document cannot be located

I've encountered some challenges while developing a login system and I'm struggling to find a solution. I've experimented with different options involving find() and findOne(), but none seem to work for my specific case. Below is the initial ...

What is the proper way to utilize the value of a Node.js promise in a different function?

In my Node.js application, I have two functions defined. The first function is structured like this: function checkAdd ( address /* : string | void */ ) /* :Promise<Object[]> */ { var convertToLowerCase = address.toLowerCase() return Promi ...

Obtaining images from the backend within a component's TypeScript file in a MEAN stack application is a

In my component.ts file, I am looking to retrieve images from the backend/images folder as Image objects. The paths of these images are stored in the database. this.productsService.getProduct(this.editId).subscribe(productData => { this.name = prod ...

What is preventing me from running the npm run dev command? (node.js/express.js/typescript)

I'm having trouble running npm run dev for my project (Node.js / Express.js / Typescript). I've followed the instructions in the links below but I still keep getting errors. PS C:\Users\Yasser\Documents\WorkspaceNodeJS\M ...

Issue: ENOENT - The specified file or directory, './views/s.ejs', does not exist in Node.js Express

Encountering an error when attempting to render a file from the 'views' directory in the 'routes'. The specific error message is as follows: Error: Valid Login { [Error: ENOENT: no such file or directory, open './views/s ...

Customize your Joi message using the .or() method

I'm attempting to personalize a message for the .or() function in Joi, similar to this: https://i.stack.imgur.com/68dKx.png The default message from Joi is as follows: Validation Error: "value" must contain at least one of [optionOne, optionTwo] ...

What is the method to provide function parameters without executing the function?

I'm searching for a solution to obtain a function that requires a parameter without actually invoking the function. Example of current malfunctioning code: const _validations = { userID: (req) => check('userID').isString().isUUID(&apo ...

Controller encounters a error when requiring a module

Struggling to set up Stripe for my app, I've encountered some issues with the module implementation. Typically, I would require a module at the top of the file to use it. However, in the paymentCtrl file, when I do this, it doesn't work and I rec ...

Building an application using NodeJs and Express, where the response is triggered after an

As a Java developer looking to organize my code, I've split it into Routes and Services. Note: While I may not be an expert in Node.js. Service Code: UserService.prototype.findUser = function(userId) { var self = this; container.db.users.findOn ...

Guide on using $lookup with aggregation in Mongoose when dealing with a foreign key within a nested subarray

I am attempting to join three tables in my express-mongo project. One of the tables is named Product and looks like this: Product: _id:5f92a8dfad47ce1b66d4473b name:"Freno 1" createdFrom:5f648f7d642ed7082f5ff91f category:5f92a00c4637a61a397320a1 descripti ...

The function soap.createClientAsync is not defined and is throwing a TypeError

Encountering an issue with the soap npm module while developing an application in Meteor. Here is the code snippet causing the error: soap.createClientAsync(url).then((client) => { return client.someMethod(soapArgs, function(err, result) { ...

Guide to deploying an AngularJS application on Heroku with Node.js without the use of yeoman

I am currently working on deploying a Hello World build using AngularJS in Heroku with Node.js, incorporating multiple views (partials). Initially, I successfully deployed a basic Hello World without utilizing ngRoute, which means without partials. Howeve ...

What is the best way to eliminate an object from an array of objects depending on a certain condition?

I have an array of objects structured like so: data = [ { "name":"abc", "email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa9b9899ba9d979b9396d4999597">[email protected]&l ...

Navigating Angular.js: finding my way to the endpoint paths

Despite my best efforts and extensive research, I find myself in need of assistance! I have a web application that utilizes node and express on the server side, with Angular on the client side. My issue lies with angular routing. IMPORTANT DETAILS My cur ...