I have read this post on an error with node in Sublime Text 2, this post on finding where node was installed, and this post on what seems to be the same issue, but none of them have helped so far. I would also prefer to use node.js. Please bear in mind, I am a programming newbie, so descriptions of locations of directories will have be absolute path names in order for me to understand.
I followed the instructions here, and my Node.sublime-build file looks like this:
{
"cmd": ["node", "$file", "$file_base_name"],
"working_dir": "${project_path:${folder}}",
"selector": "*.js"
}
I restarted Sublime Text 2, but it didn't work. I restarted my computer, but to no avail.
Currently, /usr/local/bin is where node is stored, and my $PATH contains that directory. At least, I think. My $PATH (I am in a bash_profile) looks like this:
-bash: /Users/David/.rvm/gems/ruby-2.0.0-p353/bin:/Users/David/.rvm/gems/ruby-2.0.0-p353#global/bin:/Users/David/.rvm/rubies/ruby-2.0.0-p353/bin:/Users/David/.rvm/bin:/usr/local/heroku/bin:/Users/David/.rbenv/shims:/Users/David/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin: No such file or directory
I think the solution may be found in the line in the Sublime Text 2 console error messages that reads,
[path: /usr/bin:/bin:/usr/sbin:/sbin]
Do I need to insert /usr/local/bin: into it? If so, how? I am running Mac OS X 10.7.5. Even if there's another thread that I haven't found, I'd gladly forgo reputation points in order to get the solution to my problem.
Cheers!
There are three options for getting your build systems to work.
First, you can edit your Node.sublime-build file to look like this:
{
"cmd": ["/usr/local/bin/node", "$file", "$file_base_name"],
"working_dir": "${project_path:${folder}}",
"selector": "*.js"
}
by adding /usr/local/bin/ to the beginning of the node command to give its fully qualified path.
Alternatively, since you're on Lion (this doesn't work on Mt Lion), you can alter the path for Dock-launched programs (by default it's /usr/bin:/bin:/usr/sbin:/sbin, as you've seen). From Terminal, run the following:
launchctl setenv PATH $PATH
(you may have to prefix it with sudo, I'm not sure). The, run:
osascript -e 'tell app "Dock" to quit'
and restart Sublime. This has the advantage of allowing other build systems (I'm especially thinking of Ruby, since you're using RVM) to work out of the box, without messing around with their .sublime-build files as well. For this and the next option, you'll need to remember to update the path when you update Ruby.
The third option, which is necessary on Mountain Lion (not sure about Mavericks) is outlined in my answer here. Basically, you need to edit /etc/launchd.conf (or create it if it doesn't exist) to define PATH, then save and reboot. This is necessary because the launchctl command on 10.8 doesn't do what we want it to do. This option may also work on Lion, but I haven't tested it, since I had already upgraded to Mt Lion before I developed it.
I hope this all helps. Good luck!
Related
I'm trying to use the "node-tesseract-ocr" module with electron to perform some basic image-to-text translations, but I'm having issues that I cannot seem to figure out, for the life of me. I'm using the exact same code as provided in the example (seen here: https://www.npmjs.com/package/node-tesseract-ocr), except I've changed the "lang" parameter for the configuration to the name of my custom .traineddata file. I've installed Tesseract manually alongside this, and have set the PATH variables for Tesseract ("C:\Program Files\Tesseract-OCR" and "C:\Program Files\Tesseract-OCR\tessdata"), and have placed the .traineddata file inside of the \tessdata folder.
Here's the error:
Command failed: tesseract "./screen.png" stdout -l mc --oem 1 --psm 3
Error opening data file C:\Program Files\Tesseract-OCR/tessdata/mc.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.
Failed loading language 'mc'
Tesseract couldn't load any languages!
Could not initialize tesseract.
I have no idea why the slashes swap midway through the path to the .traineddata file; I'm assuming this is the issue, but I have no idea how to fix this, as it seems to be an issue with Tesseract itself.
Did I install an incorrect version or something? (I installed Tesseract using "tesseract-ocr-w64-setup-v5.2.0.20220712.exe" from "https://digi.bib.uni-mannheim.de/tesseract/", as suggested by "https://medium.com/quantrium-tech/installing-and-using-tesseract-4-on-windows-10-4f7930313f82").
Everything works perfectly fine when using "eng" as the language, except the characters are not always read properly (since I'm attempting to read characters from a game, rather than handwriting/a standard English font, which is why I need the custom .traineddata file to work).
Any help is appreciated.
I used the installation from https://github.com/UB-Mannheim/tesseract/wiki and it seems to work now. Not sure why the other installation was bugged, but oh well.
Is it possible to have code like this:
#! /usr/local/bin/node
console.log("Hello world")
That I can also run in the browser?
I have a script that I run locally and want to run it in the browser but right now I need to "recompile" it for the browser target only to remove the hashbang line.
I can't think of a way around it. Any ideas?
Edit: my use is that I don't want to have 2 files, as I want to be able execute the current file while working on it, and also serve it via the web. I think the solution is going to have to be to either compile it for the browser to a second file or to use an alternative to #! that plays nice with javascript.
If you only ever use bash, you can take advantage of one feature (?!) of bash: bash executes scripts without a shebang using bash. Other shells may leave it to the OS, which would usually use /bin/sh instead. For example:
bash-5.0$ echo 'echo $1 $BASH_VERSION' > foo.sh
bash-5.0$ for sh in sh bash dash ksh zsh; do $sh -c "./foo.sh $sh"; done
sh 3.2.57(1)-release
bash 5.0.7(1)-release
dash 3.2.57(1)-release
ksh
zsh 3.2.57(1)-release
(/bin/sh being a link to an old version of bash here on macOS.)
So, you could have a file like this:
///usr/local/bin/node <(tail -n +1 "$0"); exit $?
console.log("Hello world")
If you run this in a browser, or other means of running JavaScript, the first line should be ignored as a comment.
If you run this as a script in bash, the first line tells it to run ///usr/local/bin/node, using process substitution with tail to feed the rest of the file to node, and then exits:
bash-5.0$ cat foo.js
///usr/local/bin/node <(tail -n +1 "$0"); exit $?
console.log("Hello world")
bash-5.0$ ./foo.js
Hello world
This trick might work with ksh as well. The /// at the beginning of the path shouldn't cause problems - three or more / at the start of a path are equivalent to a single /.
But I would strongly encourage you to use a wrapper script instead, as suggested by the comments.
I've been reading through a lot of stuff on this site and I cannot seem to find an answer to my need.... to the point:
I need to copy 1 file to all folder in C:\program files dir, however I'm trying to find a way that I wont need to specify the full path...for a rough example I can
REN F:\source\*.bat *.exe
(or .mp3 or .jpg or .vbs etc etc)
the above commands will rename all *.bat files to *.exe files, without specifying a path
so I'm looking for a similar command line in a batch to move 1 specific file to multiple folders in a dir without specific paths...
I have tried %~d0\ and %programfiles% but nothing seems to work for me....
I still do not fully understand the use case for this, but here is something that will copy a file into each subdirectory below the user's "Program Files" directory. Once you are sure that the copies you expect would be done, remove the -WhatIf from the Copy-Item cmdlet.
Get-ChildItem -Directory -Path $Env:ProgramFiles |
ForEach-Object {
Copy-Item -Path 'C:\src\t t t.txt' -Destination $_.FullName -WhatIf
}
If you must run it from a cmd.exe shell, put the code above into a file named with a .ps1 extension and run:
powershell -NoProfile -File copyit.ps1
Notes:
It is important to use the environment variable ProgramFiles because the actual directory name may be in a language you do not know.
There may be permission issues with writing to these directories. Try using Run as Administrator.
Yes, there are certainly .bat file script ways to do this. The future Microsoft direction is PowerShell. Might as well start grocking it now.
I am planing to make something similar as lodash custom builds. So in general I want to let user write command like:
lodash category=collection,function
Which create custom module just with category i specified
I read few tutorials how to run scripts with npm bin. Just in case I understand something wrong I write it what i think.
So if I have package.json with this part:
"main": "bin/index.js",
"bin": {
"snippet": "bin/index.js"
},
and I npm install -g console should listen for command snippet and when i write it it run the script index.js in folder bin.
This part looks it works correctly for me. When i have something simple in my index.js i.e. console.log('It Works').
In standard situation you want to let user pass parameters to script. So i found out that all parameters should be in variabile process.argv.
The process.argv property returns an array containing the command line
arguments passed when the Node.js process was launched. The first
element will be process.execPath. The second element will be the path
to the JavaScript file being executed. The remaining elements will be
any additional command line arguments.
So i simply console.log it and run script.
If I run script via command snippet -f -a
Output is : [ 'node', 'path/to/file' ]
If i run script via node bin/index.js -f -a
Output is: [ 'node', 'path/to/file', '-f', '-a' ]
I dont understand that, its same script but different output. However I try it looks like when i call script via bin command it never pass parameters.
Is here someone who have experience with this? And advise me what i am doing wrong?
Or alternativly is there some other way how to make this?
Thanks for any advise.
It take a time however I have a solution now so hope it help someone later.
Where was a problem:
I noticed that my windows has default program to run .js file set to NODE.js and because it's default setting of course all .js files are opening without parameter.
So in my case every .js file open with NODE no matter what, I try to changed it to open with something like PSPAD or similar but this basicly open editor instead of execute file.
How did I fix it:
Instead of using executing .js directly with something I make my ./bin/index.js binary file (basicly removed .js suffix)
Added #!/usr/bin/env node on top of index file
Goes to package.json and changed all dependency on ./bin/index.js to ./bin/index
Woala! it works :)
p.s. As I mentioned at start I believe there is an option to run this with .js as well but I wasn't able to find it. So please if anyone will find it let me know.
Thanks
I can't see the output to console.log when I build JavaScript files using a custom Node.js build system in Sublime Text (build 3083) on Linux.
When I try to build jstest.js which contains just console.log("Hello world!"); Sublime Text's console reports Running /usr/bin/node /home/sophie/scripts/jstest.js and that the build is successful, but I do not see the expected "Hello world!" output.
If I execute node jstest.js in my Linux terminal, "Hello world!" is properly output, as expected.
I have node installed at /usr/bin/node. The file jstest.js is saved to disk (apparently, Sublime Text will not build unless the file is saved). I'm using the following custom build system (and it is selected before building, of course):
{
"cmd": ["/usr/bin/node", "$file"],
"selector": "*.js"
}
I've tried setting the location to just "node" and also removed the "selector" option, but neither had any effect, there's still no console.log output.
I've looked through a few similar questions and answers here (that's where I obtained the build system code), but nothing has solved the issue for me, yet. Any suggestions?
Apparently, the issue was a bug either with Sublime Text itself, or the Material Design (https://github.com/equinusocio/material-theme) theme I am using. To solve the issue, I did the following:
Switch to the default Sublime Text theme
Build the JS file using the custom Node.JS build system, confirm console.log output
Switch back to desired theme
Build the file again, console.log output should be visible
That worked for me, at least.
Try dropping the semi-colon at the end of your line of code, which would give you the following:- console.log("Hello Javascript World!") There is no semi-colon at the end of the code line, save the file and build. Be sure Node is selected as the build system.
An alternative would be to use: debug("output here");
This would replace console.log("output here");