PY_NEWBIE
PY_NEWBIE

Reputation: 77

Is there a way to send data from javascript to an exe file

I was making a simple website where when you put in an username and password, It would send it to a c++ executable that would save the data in a txt document.

the executable works fine, but I can't find a way to send the data to the executable.

I tried window.open(), but then, It started to download the exe file.

this is the code of the c++ executable

#include <fstream>
#include <iostream>
using namespace std;
char main () {
   char name[100];
   char password[100];
   cin >> name;
   cin >> password;

   ofstream outfile;
   outfile.open ("data.txt", ios_base::app);
   outfile << name <<"; " << password << endl;
   outfile.close();
}

Upvotes: 1

Views: 510

Answers (1)

Javier Silva Ort&#237;z
Javier Silva Ort&#237;z

Reputation: 2982

What you're trying to do is called interproccess comunication. It's quite common, however, in the traditional sense, it can't be done between a web page javascript and a standard desktop app. Still, you can emulate it, one possible way is using sockets/WebSockets in your desktop app and WebSockets in your web page's javascript. The other way could be implementing a simple REST API with two endpoints, one on the app and one on the web page server.

The socket approach is easier, for more info on it, check this post. Also check this WebSocket tutorial and this C++ WebSocket library.

Following up on your comment, all of this can be done in a single computer, in fact, that's what I had in mind when answering.

Upvotes: 1

Related Questions