rabchev / web-terminal

Web-Terminal is a terminal server that provides remote CLI via standard web browser and HTTP protocol.
MIT License
442 stars 138 forks source link

Get 'command not found' error for some command (like npm) #8

Open akfish opened 10 years ago

akfish commented 10 years ago

Environment

Commands that run perfectly in a native terminal but won't work with web terminal:

One thing they have in common is that they are all commands of globally installed node modules.

akfish commented 10 years ago

I did some more testing and found the cause. In Windows, node creates a *.cmd file in %USERPROFILE%\AppData\Roaming\npm for each global module command. While the native cmd.exe doesn't need the file extension to find the command, the child_proccess.spawn does.

So to get those commands listed above working, just add the file extensions:

Though it's nice to fix this or at least document it.

rabchev commented 10 years ago

I will fix it next week, I don't have Windows machine at home.

rabchev commented 10 years ago

I'm not sure what's the best way to resolve this issue. At first I thought I would just add .cmd at the end if the command isn't found, but that is really lame. Probing seems like a bad idea in the first place and there might be other extensions like .bat that wouldn't work either.

There is one workaround though, you can start web-terminal with -h (--shell) option, like this:

  $ web-terminal -h cmd

Do you have any better ideas?

akfish commented 10 years ago

I would try to emulate what the cmd does:

  1. Load all folder paths specified by PATH environment variable
  2. Search executable by file name in those folders
  3. Spawn with full path Note that there could be some security issues to expose a system like that. It would be nice to have the option to disable this feature. An alternative as opposed to use PATH is to give users the ability to config search paths or command white-list/alias-list in config files.
akfish commented 10 years ago

@rabchev Check out this package: https://www.npmjs.org/package/which Found it when working on another project. It should do the trick.

michaelpalumbo commented 6 years ago

Environment Windows 10 x64 Node 10.x

Following up on this thread, some commands are not recognized, such as 'npm', 'dir', 'ls', 'start'.