Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got error when I try to run js code #61

Closed
mattma opened this issue Mar 10, 2014 · 52 comments
Closed

Got error when I try to run js code #61

mattma opened this issue Mar 10, 2014 · 52 comments

Comments

@mattma
Copy link

mattma commented Mar 10, 2014

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
Copy link
Member

rgbkrk commented Mar 10, 2014

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
Copy link
Member

rgbkrk commented Mar 10, 2014

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

@mattma
Copy link
Author

mattma commented Mar 10, 2014

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
Copy link
Contributor

Lbatson commented Mar 10, 2014

@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
Copy link
Member

rgbkrk commented Mar 10, 2014

@mattma Where are you running Atom from?

The icon/Applications or from the console?

@mattma
Copy link
Author

mattma commented Mar 10, 2014

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
Copy link
Contributor

Lbatson commented Mar 10, 2014

@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
Copy link
Member

rgbkrk commented Mar 10, 2014

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. :)

👏 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
Copy link
Author

mattma commented Mar 10, 2014

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.

@mattma mattma closed this as completed Mar 10, 2014
@rgbkrk
Copy link
Member

rgbkrk commented Mar 10, 2014

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
Copy link

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 👍 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
Copy link
Member

rgbkrk commented Mar 11, 2014

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

@aesarius
Copy link

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
Copy link
Member

rgbkrk commented Mar 11, 2014

Alright, updated env suggestion in 655ccfb.

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
Copy link
Member

rgbkrk commented Mar 11, 2014

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
Copy link

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

@rgbkrk
Copy link
Member

rgbkrk commented Mar 11, 2014

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

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

@aesarius
Copy link

Yeah ok this is rather interesting!
Nice catch 👍

@hansrodtang
Copy link
Contributor

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
Copy link
Member

rgbkrk commented Mar 26, 2014

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

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

@hansrodtang
Copy link
Contributor

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
Copy link

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
Copy link

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.

@jbavari
Copy link

jbavari commented Jul 13, 2015

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
Copy link

oddysee commented Aug 5, 2015

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

@BramVanroy
Copy link

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
Copy link

mokhosh commented Aug 11, 2015

W10 +1

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

@hurrymaplelad
Copy link
Collaborator

@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
Copy link

ghost commented Oct 14, 2015

+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
Copy link
Member

rgbkrk commented Oct 14, 2015

@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
Copy link

ghost commented Oct 15, 2015

@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
Copy link
Member

rgbkrk commented Oct 16, 2015

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

@ersiner
Copy link

ersiner commented Dec 17, 2015

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

@turotulco
Copy link

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
Copy link

ToSeven commented Dec 27, 2016

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
Copy link
Collaborator

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

@SarbajitNandy
Copy link

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
Copy link

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
Copy link

ghost commented Jul 3, 2017

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?

  • Dan

@miromarszal
Copy link

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

@Kristi92
Copy link

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
Copy link

can anyone help me with this issue please
?

@bhflm
Copy link

bhflm commented Jan 29, 2019

image

Ubuntu 16.04 😕

@MStonehouse
Copy link

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
Copy link

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
Copy link

MCilento93 commented Dec 6, 2020

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
Copy link

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

@MCilento93
Copy link

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

@luciferchase
Copy link

I dig through this thread and tried running atom from the cmd itself still I am unable to run any Kotlin file. A little help?
image

@M5planetX
Copy link

M5planetX commented Apr 19, 2022

Prerequisites

Description

Steps to Reproduce

  1. Install atom
  2. Install GitHub for Windows
  3. Install atom-script
  4. Run atom

Expected behavior:

normal atom welcome screen

Actual behavior:

Versions

Atom: 1.60.0 x64
Electron: 9.4.4
OS: Microsoft Windows 10 Home
Thrown From: script package 3.32.2

Stack Trace

Failed to activate the script package

At Cannot find module 'temp'
Require stack:
- C:\Users\Pc\.atom\packages\atom-script-3.32.2\lib\grammar-utils.js
- C:\Users\Pc\.atom\packages\atom-script-3.32.2\lib\grammars\index.js
- C:\Users\Pc\.atom\packages\atom-script-3.32.2\lib\grammars.js
- C:\Users\Pc\.atom\packages\atom-script-3.32.2\lib\code-context-builder.js
- C:\Users\Pc\.atom\packages\atom-script-3.32.2\lib\script.js
- C:\Users\Pc\AppData\Local\atom\app-1.60.0\resources\app.asar\static\index.html

Error: Cannot find module 'temp'
Require stack:
- C:\Users\Pc\.atom\packages\atom-script-3.32.2\lib\grammar-utils.js
- C:\Users\Pc\.atom\packages\atom-script-3.32.2\lib\grammars\index.js
- C:\Users\Pc\.atom\packages\atom-script-3.32.2\lib\grammars.js
- C:\Users\Pc\.atom\packages\atom-script-3.32.2\lib\code-context-builder.js
- C:\Users\Pc\.atom\packages\atom-script-3.32.2\lib\script.js
- C:\Users\Pc\AppData\Local\atom\app-1.60.0\resources\app.asar\static\index.html
    at Module._resolveFilename (internal/modules/cjs/loader.js:797:17)
    at o._resolveFilename (electron/js2c/renderer_init.js:43:689)
    at Function.get_Module._resolveFilename (~/AppData/Local/atom/app-1.60.0/resources/app/static/<embedded>:11:157942)
    at Module.require (/app.asar/static/index.js:61:43)
    at require (~/AppData/Local/atom/app-1.60.0/resources/app/static/<embedded>:11:149229)
    at /packages/atom-script-3.32.2/lib/grammar-utils.js:6:24)
    at /packages/atom-script-3.32.2/lib/grammar-utils.js:128:28)
    at Module.get_Module._compile (~/AppData/Local/atom/app-1.60.0/resources/app/static/<embedded>:11:149913)
    at Object.value [as .js] (~/AppData/Local/atom/app-1.60.0/resources/app/static/<embedded>:11:153507)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module._load (electron/js2c/asar.js:769:28)
    at Module.require (/app.asar/static/index.js:72:46)
    at require (~/AppData/Local/atom/app-1.60.0/resources/app/static/<embedded>:11:149229)
    at /packages/atom-script-3.32.2/lib/grammars/index.js:12:24)
    at /packages/atom-script-3.32.2/lib/grammars/index.js:614:29)
    at Module.get_Module._compile (~/AppData/Local/atom/app-1.60.0/resources/app/static/<embedded>:11:149913)
    at Object.value [as .js] (~/AppData/Local/atom/app-1.60.0/resources/app/static/<embedded>:11:153507)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module._load (electron/js2c/asar.js:769:28)
    at Module.require (/app.asar/static/index.js:72:46)
    at require (~/AppData/Local/atom/app-1.60.0/resources/app/static/<embedded>:11:149229)
    at /packages/atom-script-3.32.2/lib/grammars.js:11:22)
    at /packages/atom-script-3.32.2/lib/grammars.js:46:24)
    at Module.get_Module._compile (~/AppData/Local/atom/app-1.60.0/resources/app/static/<embedded>:11:149913)
    at Object.value [as .js] (~/AppData/Local/atom/app-1.60.0/resources/app/static/<embedded>:11:153507)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module._load (electron/js2c/asar.js:769:28)

Commands

Non-Core Packages

script 3.32.2 

Additional Information

Hello all,
I've installed atom, GitHub for windows, and the atom-script-3.32.2 package successfully but I am unable to run any code using ctrl+shift+B and whenever I open atom I get this message.
Pls help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests