1

Quite simply, I have a link to dart2js in my /usr/local/bin/ which throws repeated erros when run.

I ran

sudo ln -s /Users/macbook/Development/dart/dart-sdk/bin/dart2js /usr/local/bin/dart2js

When running dart2js from terminal, I'm presented with

...
/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

I imagine I'm simply using links incorrectly, but I'm not knowledgable enough to know why.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Cereal
  • 3,699
  • 2
  • 23
  • 36

1 Answers1

0

I run into this a while ago and posted this issue Can't run dart command line script using a symlink

I also added a workaround which may help in your situation as well - you probably need to adapt it a bit but it should get you started.

A workaround I use now is to create a bash script named 'testscript' in the same directory as testscript.dart and link to this script instead

I lookup the current directory of the bash script and start the dart script (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]}

Instead of getting the command's (symlinks) name with io.Platform.script I have to pass it as an argument to have it available inside the dart script (I use the name of the symlink used to start the script like an argument inside the dart script) This way I have to distinguish if the script was started directly and use io.Platform.script and args[0] otherwise.

I think this should all be easier.

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567