3

I created webstorm external tool which throws some errors but running the same task from terminal works fine.I understand that this is because when run in webstorm the $PATH variable is set different from that of the terminal case. There isn't any option to set environmental variable while creating an external tool. How do I set $PATH for external tools in webstorm/rubymine? External tool I was creating was a grunt task and OS is ubuntu if that helps.

This is the error: Error running grunt server: Cannot run program "grunt": error=2, No such file or directory

Dylan Corriveau
  • 2,561
  • 4
  • 29
  • 36
Kamal Reddy
  • 2,610
  • 5
  • 28
  • 36

4 Answers4

5

There is a feature request to support environment variables for the external tools.

Current workarounds:

  • Make GUI apps environment the same as in Terminal per this answer
  • Run your script via bash --login (external tool runs bash login shell that sets the environment and executes the script name passed as a parameter)
Community
  • 1
  • 1
CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
1

For OSX:

Open ‘/Applications/Webstorm.app/Contents/Info.plist’ in your favorite editor.

Find the following section and replace [Your Path Value]

<key>LSEnvironment</key>
<dict>
    <key>PATH</key>
    <string>[Your Path Value]</string>
</dict>

Then run:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/WebStorm.app

I got this fix from a fantastic article by Ifeanyi Isitor

http://ify.io/getting-webstorm-external-tools-to-work-on-webstorm-on-osx

npatten
  • 171
  • 1
  • 1
  • 6
0

I've found a dirty-workarround for linux. Create a file (e.g phpstorm_wrapper) and put this inside:

#!/bin/bash
if [ $# > 1 ]; then
  exec "$@"
else
 eval "$1"
fi

Save and make it executable.

USAGE:

Now you can run the wrapper-script as Program: in your "external tools" and set all Parameters you like to the Arguments inputfield.

The script will execute it and return the result of it.


If you need to use ENV-Variable, you must use env command like this:

env FASTLANE_JSON_KEY_FILE=./release_manager.json fastlane test

enter image description here


If you need to use | (pipes), phpstorm put it in quotes. To be able to execute commands which use |, encapsulate the whole Textfield "Arguments" in the external tool dialoge in quotes.

Example:

enter image description here

suther
  • 12,600
  • 4
  • 62
  • 99
0

Here are some workarounds that I use on Windows until the feature is supported by IntelliJ. Please star the feature-request

cross-env

In my projects, I already have cross-env installed, so I can easily reuse it in the External Tools dialog, e.g.

  • Program: D:\dev\YOUR_PROJECT\node_modules\.bin\cross-env.cmd
  • Arguments: MY_ENV_VAR=value MY_ENV_VAR2=1 D:\dev\SomeExe -exeOptions

Shell Script Workaround

note: with this method, the color output on the console did not work (i.e. the ansi-color codes are not interpreted)

My workaround is to use a Shell Script run configuration

  • set Execute to Script text and simply start the executable (with optional args)
  • here we can also set the working dir and env vars
  • note: my terminal is set to git-bash: thus I must use ./ before the exe name

enter image description here

TmTron
  • 17,012
  • 10
  • 94
  • 142