atom-community / atom-script

:runner: Run ( scripts | selections | source ) in Atom
https://atom.io/packages/script
MIT License
733 stars 269 forks source link

Got error when I try to run js code #61

Closed mattma closed 10 years ago

mattma commented 10 years ago

I just installed the script plugin today on the latest atom editor 0.69.

I have a file named test.js, I defined a test function like it

function test() {
    console.log('hello world');
}
test();

Then I hit cmd-i, I got an error

 execvp(): No such file or directory

Tried in the readme shell script ls example, it did not work for me at all. I am using the script@2.0.2 , is there any special setup to use this plugin? thanks

rgbkrk commented 10 years ago

Right now the plugin is using node to run javascript code. We need a config setup to let you specify your executable of choice (jasmine?). I'll hack on this tonight to get this feature in for you if this is the problem. If you're just wanting to run client side javascript, we don't have a good setup for that. I'd recommend @ardcore's https://github.com/ardcore/atom-safe-eval.


If you do have node, but it's still not running, it may be an environment issue. Script relies on the environment variables that Atom loads with. Atom run from a shell is different than Atom run from the icon/Applications menu. Run env in a bash script from Atom using script to see what I mean.

As for the absolutely useless error message being passed to you, that needs fixing. Since we're using Atom's BufferedProcess we don't have direct access to node's child_process.spawn which we would need in order to provide more useful error messages in the display window:

child.stderr.on('data', function (data) {
  if (/^execvp\(\)/.test(data)) {
    console.log('Failed to start child process.');
    // Let user know the executable was unavailable
  }
  // Other logic
});

An alternative for us of course is to check for the existence of the executable first. Not sure how I feel about that, but it may be necessary.

rgbkrk commented 10 years ago

Whoa, wait. I just re-read what you said about the shell script example. Bash doesn't work either?

mattma commented 10 years ago

Well, I re-tested the shell script, ls -las. it works. :) what happened is, I created a shell file but I did not save it. When i run the script, it shows the green check mark but without the result. After I read your replied, I tried again with saved file, it works as promised.

I do have node in my system. I just want to test the script plugin, and no specific purpose on running on client or server side. Well, I tried with server side node code, it still could not run. Could you just provide an example that the script plugin could work as it advertised. So that I could have a reference how to use it. Now, i just simply put any console.log code in coffee or plain js, it does not have a result excerpt an Error code execvp(): No such file or directory every single time.

Maybe it needs a specific file structure?

Lbatson commented 10 years ago

@mattma I'm able to run the function you posted above and get the appropriate output both with and without saving the file as shown below. However, the issue you're experiencing is probably because you're launching atom from the dock and not via the command line using the atom command. If you open via the command line all should work properly.

screenshot 2014-03-09 22 08 29 screenshot 2014-03-09 22 10 18

rgbkrk commented 10 years ago

@mattma Where are you running Atom from?

The icon/Applications or from the console?

mattma commented 10 years ago

Yes, from icon.Applications. How could I run from the console? Instruction please.

I am experienced user of Sublime Text, and i think this plugin could essentially be the build tool for atom. :)

Lbatson commented 10 years ago

@mattma you can launch Atom from your terminal. Open up a terminal window and type atom -h for more information. If it says something like command not found, go to the menu bar Atom > Install Shell Commands

rgbkrk commented 10 years ago

If you install the cli tools:

screen shot 2014-03-09 at 10 48 44 pm

You can run atom from the cli. It picks up your environment variables that way, as well as opening the project you're currently in.

Make sure to fully quit Atom first.

I am experienced user of Sublime Text, and i think this plugin could essentially be the build tool for atom. :)

:clap: That would be awesome! We'd probably need a name change for that, but it's becoming clear that people want a unified output pane for running crud.

mattma commented 10 years ago

First, it works as it advertised.

2nd, I do have atom apm installed in my machine. I think I do have atom command available, or I really do not have it.

Anyway, after I tried that, it works great.

Question, can this one run mocha command for testing? can I execute any cli command in there like rm -rf ./filename? just tried and it did not work. If you need any help, feel free to ping me and i will make a pull.

rgbkrk commented 10 years ago

Yay! Glad that works for you. We're going to update the README to make sure the cli vs. icon running is clear.

Question, can this one run mocha command for testing?

Mocha may be better suited to @tombell's https://github.com/tombell/test-status.

However, I'm currently hacking away on the config settings right now so that you can change it to use your preferred command for each language.

can I execute any cli command in there like rm -rf ./filename?

You can run any cli commands that don't need input using a bash script. Keep in mind however that the current working directory that it's operating from is wherever Atom was opened from.

aesarius commented 10 years ago

Hey there, Awesome work there mate! Just wanted to let you know that I also had to dig up this tread to understand why the package wasn't working for me also... Running Atom from the command line did the trick :+1: but it would be good if you could include this in the readme.md indeed. Also, how could one set this up to be able to start from the "icon" just because I am using Alfred to open most of my stuff and it would be great not having to go through the term. Cheers!

rgbkrk commented 10 years ago

@aesarius - Thanks for poking me on this. I'll edit it now.

aesarius commented 10 years ago

No worries mate. Sorry to bother but what about starting Atom form Alfred then? How would I go and set-up the env in that case? Through shebang or something like this? Thanks mate.

rgbkrk commented 10 years ago

Alright, updated env suggestion in 655ccfb35e1e4d4c4b15267c8bae9b7d9be8256e.

On to launchctl. I covered this a bit in #5, but issues/PRs clearly aren't the documentation.

I don't have Alfred, so if this doesn't work let me know.

What you'll want to do is setup launchctl to use the PATHing from your normal setup. This can either be done programmatically:

launchctl setenv <key> <value>

or in ~/.launchd.conf:

$ cat  ~/.launchd.conf
setenv KEY 'value'

Someone on StackOverflow has a ridiculous solution for changing launchctl as your export vars in bash.

Let me know what you think of these, and feel free to update the README. I'm always happy to review and merge PRs!

rgbkrk commented 10 years ago

Yet another method is setting up launchctl as part of your bash profile:

p=$(launchctl getenv PATH)
launchctl setenv PATH /my/new/path:$p

That would get executed on every single terminal that is opened though, so nevermind that one.

aesarius commented 10 years ago

Ok mate. Will have a look at this when I get a sec :+1: Thanks a lot for your answer!

rgbkrk commented 10 years ago

You've truly made me curious. You can also modify your init script:

screen shot 2014-03-11 at 2 27 15 pm

aesarius commented 10 years ago

Yeah ok this is rather interesting! Nice catch :+1:

hansrodtang commented 10 years ago

Adding the stuff I need to ~/.bashrc seems to work for me in GUI and the terminal, just wanted to share that in case anybody wants to try it. Still frustrating about the seeming ambiguity of all the options of settings environment variables.

To update the terminal you might need to use source ~/.bashrc. I used that since I rarely reboot for anything.

rgbkrk commented 10 years ago

@hansrodtang I definitely don't know the best practice here.

Has anyone seen a good discussion on the forums about this?

hansrodtang commented 10 years ago

For now I just add what I need to ~/.bashrc and add

if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

to ~/.bash_profile in accordance to what I read here and here.

Seems like this is something Atom itself should fix/make more transparent to package developers since a properly equipped environment is essential to any programming tool. Getting GOPATH for Go into Atom with consistent results has been a pain, I'm glad this tweak finally made it work for me.

JediMindtrick commented 10 years ago

So I had a similar problem. I'm a mac noob, so this first bit may have been the wrong thing to do...

I had put atom into its own folder inside /Applications; so /Applications/atom/atom.app. Atom ran fine, command-line worked...life seemed happy. When I tried to use this plugin I was getting the above error...checked my path by using plugin to run env...path looked like a real one, etc...

Long story short, I removed atom from it's old location, and reinstalled as /Applications/atom.app. Now all is well :)

edmulraney commented 10 years ago

I had the same issue in Ubuntu. Here's what I did to get it working:

  1. Install mono and scriptcs (I already had mono-develop installed but if you don't want the IDE then apt-get install mono-complete I think will give you what you need without installing the IDE. For scriptcs get the dev version from github then run sudo ./build.sh)
  2. Copy the "scriptcs.exe" (src/ScriptCs/bin/Release) into a file called "scriptcs"
  3. Add the path to the Release directory containing the scriptcs executable to your PATH. My .bashrc: export PATH=$PATH:~/installs/scriptcs-dev/src/ScriptCs/bin/Release
  4. Install Atom Runner. File -> Preferences -> Packages -> Search Atom Runner
  5. Add
'runner':
  'extensions':
    'csx': '/home/user/installs/scriptcs-dev/src/ScriptCs/bin/Release/scriptcs -script'

to your config.json (ctrl shift p, config)

You should now be able to run C# files saved as .csx files by pressing ctrl shif p then type r and hit enter.

rgbkrk commented 10 years ago

@edmulraney For yours, this is actually the case of scriptcs not being a part of atom-script's grammar file. Looks like you have it working in Atom Runner (not this package) though.

edmulraney commented 10 years ago

@rgbkrk Haha oops, well spotted. Different package completely. I found this thread when searching for a solution to my scriptcs issue so hopefully someone else will find it useful..

jbavari commented 9 years ago

I've just worked around this issue on OSX.

The way I solved it was by using the fix-path module to adjust my path when running from the app file.

Hope this helps any other users with this issue.

oddysee commented 9 years ago

@jbavari How did you use fix-path for the script plugin? Is there a pull request or branch I can use?

BramVanroy commented 9 years ago

All of the discussion above seems Linux-centred. However, I'm happily running on W10 and I'm not entirely sure how I can start Atom from cmd, or with custom parameters on an icon, so the package would work. Any suggestions?

mokhosh commented 9 years ago

W10 +1

It seems to work randomly. Even if I run it from the command line.

hurrymaplelad commented 9 years ago

@oddysee Wrapped up fix-path as an atom package. You should just be able to apm install atom-fix-path or install it from the settings pane. Thanks @jbavari for the suggestion.

ghost commented 9 years ago

+1 @rgbkrk for

# init.coffee
process.env.PATH = ['/usr/local/bin', process.env.PATH].join(':')

but who knows what PATH is set to by default? I prefer just being totally explicit and setting my entire PATH. That way if a binary can't be found, I know precisely which directories need to be added.

# init.coffee
process.env.PATH = [
  "/usr/local/bin",
  "/usr/bin",
  "/bin"
].join(":")

Less is more™

rgbkrk commented 9 years ago

@naomik On Mac at least, PATH gets set by launchctl. If you want to see what it gets set to on startup, put

alert(process.env.PATH)

in your init.coffee and see what you get back.

ghost commented 9 years ago

@rgbkrk yeah I still prefer to just set what's required. I do the same in my .zshrc but maybe that's me being overly controlling.

I generally hate relying on defaults because I can never remember what they are (and they're different on a lot of platforms). It's takes more time for me to look up defaults than it does for me to write what I actually need.

rgbkrk commented 9 years ago

Yeah, I prefer to use what's in my bashrc. The problem lies in how Atom is launched (or restarted after an upgrade...) :unamused:

ersiner commented 8 years ago

You may use osx-env-sync to solve this problem on OS X for all applications in the proper way.

turotulco commented 8 years ago

Windows 7. I just went into MyComputer, chose Advanced System Settings, and pressed the button marked Environment Variables. Path is the top environment variable. Add ";C:\Python" to the end of the path (or the beginning; or whatever your python path is named). This is the environment that will be loaded every time a command prompt is spawned.

ToSeven commented 7 years ago

window10 I just run c program but script generate some terrible things , I use google to solve it ,but there is nothing so can you help me?

default

danielbayley commented 7 years ago

Just to add another solution… there's also the env-from-shell package.

SarbajitNandy commented 7 years ago

I'm a pc user. I have downloaded atom recently, and want to set it up for Python coding. Though I have already downloaded 'Script' for run codes. but facing a great problem at the time of running . though the whole code is perfect, getting this message "Python is not recognized as an internal or external command". plz help me to solve this.

miromarszal commented 7 years ago

A workaround for Win10:

  1. Right-click on the Atom shortcut
  2. Go to "Properties"
  3. Replace the path in "Target" with cmd /C atom

A side effect: the terminal window stays open.

ghost commented 7 years ago

miromarszal commented 6 days ago

A workaround for Win10:

Right-click on the Atom shortcut
Go to "Properties"
Replace the path in "Target" with cmd /C atom

A side effect: the terminal window stays open.

Hi. Let us consider this proposal. How about creating a BAT file?..

  1. Right-click on the Atom shortcut
  2. Go to "Properties" of the shortcut
  3. Copy the entry in "Target"
  4. Open a text editor such as Notepad
  5. Put in this text file the "Target" copied in (3)
  6. Insert the line " @echo off " before it.
  7. Save & close the text file as (example) openAtom.bat in the same directory as "Target"
  8. Replace the "atom.exe" with "openAtom.bat" in the "Target" of (3).

The command prompt does open,but does not remain open.

Helpful?

miromarszal commented 7 years ago

I should have thought about this one, works like a charm.

Kristi92 commented 6 years ago

Error Line Number Based runner not available for JavaScript.

If it should exist, add an issue on GitHub, or send your own pull request.

Kristi92 commented 6 years ago

can anyone help me with this issue please ?

bhflm commented 5 years ago

image

Ubuntu 16.04 :confused:

MStonehouse commented 4 years ago

For Ubuntu and Linux Mint.

Hello bhflm.

Just ran into the same problem you had. This might help.

If you installed the flatpack version from software manager Atom won't be able to find node.

Uninstall Atom.

Go to https://atom.io/ and download the .deb version.

Once downloaded double click on the deb download. A popup window will open. Click on install package.

Not only will Atom now recognize the path to node, your install is now less than 1GB (flatpack is 3.4GB)

trbielec commented 4 years ago

Workaroud for python3:

1787

If you want to use Python3 by default, you can open Atom Settings, Atom→Preferences→Open Config Folder, and open.atom/packages/script/lib/grammars/python.coffee, Changing python to python3 under 'Selection Based' and 'File Based', saving it.

MCilento93 commented 3 years ago

Nothing specific for conda? I would like to change the init.coffee suitably to startup atom (when launched by icon) in pre-activated conda env. Thank you

omarflight commented 3 years ago

how to fix this 'python' is not recognized as an internal or external command, operable program or batch file.

MCilento93 commented 3 years ago

how to fix this 'python' is not recognized as an internal or external command, operable program or batch file.

if you have python installed from official release, you should not have issues. If you are using conda you can open atom from pre-activated cmd