Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

'Command failed' in Electron app #120

Open
DavidForss opened this issue Mar 11, 2020 · 1 comment
Open

'Command failed' in Electron app #120

DavidForss opened this issue Mar 11, 2020 · 1 comment

Comments

@DavidForss
Copy link

DavidForss commented Mar 11, 2020

Hello and thanks for a great library!

I´ve got a problem with starting and stopping my local mysql process from my electron app.
( I am on macOS Catalina and mysql.server is set in my $PATH)
I can do it with both child_process spawn and child_process exec like this:

exec("sudo mysql.server start", (error, stdout, stderr) => {
  if (error) {
    console.log("error: " + error);
    console.log("stderr: " + stderr);
  }
  console.log("stdout: " + stdout);
});

and:

const child = spawn('sudo', ['mysql.server', 'start']);

child.on("exit", code => {
  console.log(`Child process exited with code ${code}`);
});
child.stdout.on("data", data => {
  console.log(`stdout: ${data}`);
});
child.stderr.on("data", data => {
  console.log(`stderr: ${data}`);
});

They both give me the sudo password prompt in my terminal though, so its not working when building the app.

So I try to do it with sudo-prompt like this:

sudo.exec("mysql.server start", { name: "My App" }, (error, stdout, stderr) => {
  if (error) {
    console.log("error: " + error);
    console.log("stderr: " + stderr);
  }
  console.log("stdout: " + stdout);
});

I get the prompt dialog like expected, but then the command fails and gives me Error: Command failed: mysql.server start in the terminal.

The strange thing is that when I run apachectl start with sudo-prompt, it works like a charm!

Any thoughts on what could cause this issue?
Thanks in advance!

@jorangreef
Copy link
Owner

jorangreef commented Sep 15, 2020

@DavidForss thanks for opening this.

Did you get this working?

If not, the issue might be this: mysql.server is set in my $PATH... whereas sudo-prompt needs you to be explicit with environment variables, because of the difficulties of making this work cross-platform.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants