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

安稳与你 提交于 2019-12-22 08:29:12

问题


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);
});

回答1:


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);
});



回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!