Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't Dart's "Process.start" execute an Ubuntu command when the command works in Ubuntu terminal?

I have command I would like to call with Dart.

The command is sonar-runner which works perfectly if I run it in a normal Ubuntu terminal. This is because I have edited the PATH in the .profile file so it becomes a global command.

However, if I wrote a simple Process.start code that should trigger the same thing:

Process.run('sonar-runner', []).then((result) {
  stdout.write(result.stdout);
  stderr.write(result.stderr);
});

I get as a response:

Uncaught Error: ProcessException: No such file or directory
  Command: sonar-runner 
Unhandled exception:
ProcessException: No such file or directory
  Command: sonar-runner 

I am guessing this is an Ubuntu configuration thing, as I have no problem running ping localhost via Dart in the same way.

What could be wrong, so that a third party application cannot find global commands when running it as a new process?

UPDATED - SOLUTION WAS FOUND

I found the solution to my problem, as described here:

Set Environment variable using Process.start

For my specific case, this code worked:

Process.run("bash", ["-c", "sonar-runner"]).then((result) {
  stdout.write(result.stdout);
  stderr.write(result.stderr);
});
like image 673
corgrath Avatar asked Oct 01 '22 00:10

corgrath


1 Answers

Try this approach run it in a normal Ubuntu terminal:

Process.run('sonar-runner', [], runInShell: true).then((result) {
  stdout.write(result.stdout);
  stderr.write(result.stderr);
});
like image 93
mezoni Avatar answered Oct 02 '22 12:10

mezoni