为什么Dart的“Process.start”当命令在Ubuntu终端工作时执行Ubuntu命令? [英] Why can't Dart's "Process.start" execute an Ubuntu command when the command works in Ubuntu terminal?

查看:482
本文介绍了为什么Dart的“Process.start”当命令在Ubuntu终端工作时执行Ubuntu命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有命令我想和Dart联系。



命令是 sonar-runner 完美如果我在一个正常的Ubuntu终端运行它。这是因为我已经编辑了 .profile 文件中的 PATH ,因此它成为一个全局命令。

但是,如果我写了一个简单的 Process.start 代码,应该触发同样的事情:

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

我作为回应:

命令:sonar-runner 
未处理的异常:
ProcessException:没有这样的文件或目录文件或目录
命令:sonar-runner

我猜这是一个Ubuntu配置的东西,因为我没有问题通过Dart以相同的方式运行 ping localhost



可能出错,第三方应用程序在作为新进程运行时找不到全局命令?



UPDATED - 解决方案已发现



我找到了我的问题的解决方案,如下所述:



使用Process.start设置环境变量



对于我的具体情况, :

  Process.run(bash,[ -c,sonar-runner])然后((result){
stdout.write(result.stdout);
stderr.write(result.stderr);
});


解决方案

尝试此方法在正常的Ubuntu终端

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


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

这篇关于为什么Dart的“Process.start”当命令在Ubuntu终端工作时执行Ubuntu命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆