Hello all. Wondering if I can get any pointers on the following code. The function “exec” serves to execute commands to the shell. I am wondering why I am still getting “This application should be launched directly from the shell or a web browser”
My code:
exec("start fivem://connect/SERVER_IP/", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
Thanks in advance.
nta
2
‘The shell’ here means the Windows shell. Why do you need to use ‘code’ to launch the game?
On my website, using a direct connection button, it uses this code to prevent the use of a meta redirect for the connection method. Instead, executes a command to the Windows Shell through JavaScript.
nta
4
I’m fairly sure exec is not something you see on a website.
It’s through Node JS using child_process. Therefore executes a shell command through the web. Here’s the full code below:
const { exec } = require("child_process");
exec("start fivem://connect/SERVER_IP/", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
EDIT:
Documentation found here: Executing Shell Commands with Node.js
nta
6
How is that ‘on your website’? Something seems off about this. Node.js is not a browser.
My server’s connector website (Where we have one click buttons to connect to server), is built primarily with Node.js. I’m unsure how so you think something is off with this.
Regardless, I found a solution. Thanks for your hard criticism, all you seem to share around this forum. I get it, you’re part of the Cfx.re team, but seriously, some people are here for support and assistance, not for someone to come and knock away every post they share.
People are looking for solutions to their problems, not people to say they’re wrong on everything they’re doing. Thanks for the pointless assistance.
nta
8
Because a website’s Node.js (usually on a server in a datacenter) wouldn’t execute code on a client system, which implies you’re omitting something, like it not actually being a website but rather an Electron app for a ‘launcher’, which is not allowed.
Instead of getting angry, you could also just have stated what you’re doing exactly, and not try to talk around things - but it’s easier to get angry and blame the person trying to help for bad form instead of admitting ‘yeah, I’;m trying to do something that’s not allowed, better not, sorry’.