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);
});
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);
});
The issue seems to be that 'sonar-runner' can not be found, have you tried with the full path ?
来源:https://stackoverflow.com/questions/25567795/why-cant-darts-process-start-execute-an-ubuntu-command-when-the-command-work