很简单,我在/ usr / local / bin /中有一个指向dart2js的链接,它会在运行时抛出重复的错误。
我跑了
sudo ln -s /Users/macbook/Development/dart/dart-sdk/bin/dart2js /usr/local/bin/dart2js
从终端运行dart2js时,我看到了
...
/usr/local/bin/dart2js: line 9: 1=/Users/macbook/Development/dart/dart-sdk/bin/dart2js: No such file or directory
/usr/local/bin/dart2js: line 9: 1=/Users/macbook/Development/dart/dart-sdk/bin/dart2js: No such file or directory
/usr/local/bin/dart2js: line 9: 1=/Users/macbook/Development/dart/dart-sdk/bin/dart2js: No such file or directory
/usr/local/bin/dart2js: line 9: 1=/Users/macbook/Development/dart/dart-sdk/bin/dart2js: No such file or directory
/usr/local/bin/dart2js: line 9: 1=/Users/macbook/Development/dart/dart-sdk/bin/dart2js: No such file or directory
... etc
我想我只是错误地使用链接,但我不知道为什么会知道。
答案 0 :(得分:0)
我刚刚遇到这个问题并发布了此问题Can't run dart command line script using a symlink
我还添加了一个可能对您的情况有所帮助的解决方法 - 您可能需要对其进行一些调整,但它应该让您入门。
我现在使用的解决方法是在与testscript.dart相同的目录中创建一个名为'testscript'的bash脚本,并链接到此脚本
我查找bash脚本的当前目录并启动dart脚本 (Getting the source directory of a Bash script from within)。
#!/bin/bash
ME="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
${DIR}/${ME}.dart ${BASH_SOURCE[0]}
我没有使用io.Platform.script获取命令的(符号链接)名称,而是必须将其作为参数传递,以使其在dart脚本中可用(我使用用于启动脚本的符号链接的名称,如参数在飞镖脚本内) 这样我就必须区分脚本是否直接启动,否则使用io.Platform.script和args [0]。
我认为这应该更容易。