简体   繁体   English

bash:终端:找不到命令

[英]bash: terminal: command not found

I am trying to write a Node.js script that will start a Node.js server in a new process, in a new command window. 我正在尝试编写一个Node.js脚本,该脚本将在新的命令窗口中的新进程中启动Node.js服务器。

I believe I am close. 我相信我很亲近。 I have this: 我有这个:

var n = cp.spawn('sh', [ 'start-server.sh' ]);

the contents of start-server.sh are like so start-server.sh的内容如下

#!/usr/bin/env bash
node bin/www

this starts the server successfully, but it doesn't open a new terminal window, so I can't see any of the stdio of the spawned process. 这将成功启动服务器,但不会打开新的终端窗口,因此看不到任何已生成进程的stdio。

So I am thinking that I should open a new terminal window in the bash script and then run the node command, so then the bash script contents would become 所以我想我应该在bash脚本中打开一个新的终端窗口,然后运行node命令,这样bash脚本的内容就会变成

#!/usr/bin/env bash
terminal -e "node bin/www"

the problem is that "terminal" is not recognized at the command line. 问题是在命令行上无法识别“终端”。 Why is that? 这是为什么? I believe the "terminal" command should default to whatever program is being used as your default terminal application. 我相信“ terminal”命令应该默认为被用作默认终端应用程序的任何程序。

Please advise if this is the best way to do this and why "terminal" might not be recognized at the command line in OSX, thanks! 请告知这是否是最好的方法,以及为什么在OSX的命令行中可能无法识别“终端”,谢谢!

this is what is in my path 这就是我的路

echo $PATH

/Users/amills001c/.rvm/gems/ruby-2.2.1/bin:/Users/amills001c/.rvm/gems/ruby-2.2.1@global/bin:/Users/amills001c/.rvm/rubies/ruby-2.2.1/bin:/Users/amills001c/google_app_engine_stuff/google-cloud-sdk/bin:/usr/local/bin:/usr/local/bin/meteor:/usr/local/redis/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/Users/amills001c/golang/bin:/Users/amills001c/apache-maven-3.3.3/bin:/Users/amills001c/.rvm/bin /Users/amills001c/.rvm/gems/ruby-2.2.1/bin:/Users/amills001c/.rvm/gems/ruby-2.2.1@global/bin:/Users/amills001c/.rvm/rubies/ruby- 2.2.1 / bin:/ Users / amills001c / google_app_engine_stuff / google-cloud-sdk / bin:/ usr / local / bin:/ usr / local / bin / meteor:/ usr / local / redis / bin:/ usr / bin :/ bin:/ usr / sbin:/ sbin:/ usr / local / bin:/ usr / local / git / bin:/ Users / amills001c / golang / bin:/Users/amills001c/apache-maven-3.3.3/ bin:/用户/amills001c/.rvm/bin

In OS X you would normally run the command like so: 在OS X中,通常会像这样运行命令:

open -a Terminal.app /path/to/script.sh

Which would open a new terminal window and execute your script. 这将打开一个新的终端窗口并执行您的脚本。

Check the real name of the "terminal" command in your system, to check it, for example, in Ubuntu do "/usr/bin/env | grep terminal", in my case is "gnome-terminal", then use "gnome-terminal -e XXX" should work. 检查系统中“ terminal”命令的真实名称,以进行检查,例如,在Ubuntu中执行“ / usr / bin / env | grep terminal”,在我的情况下为“ gnome-terminal”,然后使用“ gnome” -terminal -e XXX“应该可以。 Hope it helps J. 希望对J有帮助。

What worked for me was this: 对我有用的是:

var cp = require('child_process');

cp.spawn('sh', [ 'start-server.sh' ], {
            detached: true,
            env: {
                NODE_ENV: process.env.NODE_ENV
            }
        });

#!/usr/bin/env bash    (start-server.sh)
open "./run-node.sh"

#!/usr/bin/env bash    (run-node.sh)
node ./bin/www.js

the open command will open the .sh file with the default app, which happens to be iterm2 for me, not terminal.app open命令将使用默认应用程序打开.sh文件,这对我来说恰好是iterm2,而不是terminal.app

the next problem I have is I have to pass paths as arguments to .sh files and I don't know how to do that yet 下一个问题是我必须将路径作为.sh文件的参数传递,但我还不知道该怎么做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM