以编程方式打开 gnome 终端并在执行 bashrc 后执行命令
我尝试构建一个小脚本来启动我的开发环境。对于该任务,我尝试打开一个带有多个选项卡的 gnome 终端,其中会自动启动 Rails 服务器和自动测试。 但
gnome-terminal --tab -e "rails server" --tab --tab
不起作用(“创建子进程时出错”)。 也
gnome-terminal --tab -e "bash -c \"rails server\"" --tab --tab`
不起作用。 有什么建议如何解决这个问题吗?
I try to build a little script to start my development environment. For that task I try to open a gnome terminal with several tabs where automatically the rails server and autotest is started.
But
gnome-terminal --tab -e "rails server" --tab --tab
does not work ("error creating the child process").
Also
gnome-terminal --tab -e "bash -c \"rails server\"" --tab --tab`
does not work.
Any suggestions how to solve that problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是我们在 超级用户处制定的一个很好的技巧
将
eval "$BASH_POST_RC"
添加到.bashrc
的末尾将每个选项卡的 BASH_POST_RC 环境变量设置为您要执行的命令,例如:
gnome-terminal --working-directory= "/home/zardoz/projects/my_rails_app" --tab -e 'bash -c "export BASH_POST_RC=\"rails server\"; exec bash"' --tab -e 'bash -c "export BASH_POST_RC=\"autotest \"; exec bash"'
@Gilles:感谢您提供的解决方案!
Here is a nice trick we worked out at Superuser
Add a
eval "$BASH_POST_RC"
to the end of your.bashrc
Set the BASH_POST_RC environment variable for each tab to that command you like to execute, e.g.:
gnome-terminal --working-directory="/home/zardoz/projects/my_rails_app" --tab -e 'bash -c "export BASH_POST_RC=\"rails server\"; exec bash"' --tab -e 'bash -c "export BASH_POST_RC=\"autotest\"; exec bash"'
@Gilles: Thanks for that solution!
暗中刺伤:为要在选项卡中运行的每个命令创建 shell 脚本,使它们可执行,并通过绝对路径调用它们,例如将其放入
/home/zardoz/bin/railsstart
< code>chmod +x 它,然后执行
如果这不起作用,我接下来要尝试的就是在开头粘贴
strace -f -o /tmp/trace.log
命令,让它失败,然后通过trace.log
挖掘,找出哪个系统调用实际上失败了以及原因(其中会有大量垃圾 - 从末尾向后读取并查找以 E 开头的全大写代码短语,例如“ENOEXEC”、“ENOENT”、“EPERM”之类。)编辑: 以下是提取所有
的方法。这些脚本之一中的 .bashrc
设置:注意:您可能需要调整
.bashrc
以便它不会执行某些仅在“真实”交互式 shell 会话中起作用的操作。除非你在 Rails 启动之前遇到奇怪的错误,否则不必担心这一点。Stab in the dark: create shell scripts for each command you want to run in a tab, make them executable, and invoke them by absolute path, e.g. put this in
/home/zardoz/bin/railsstart
chmod +x
it, and then doIf that doesn't work, the next thing I would try is sticking
strace -f -o /tmp/trace.log
on the beginning of the command, letting it fail, and then digging throughtrace.log
to find out which system call actually failed and why (there'll be a tremendous amount of junk in there - read from the end backward and look for all-capitalized code phrases starting with E, like "ENOEXEC", "ENOENT", "EPERM", sort of thing.)EDIT: Here's how you pull in all the
.bashrc
settings in one of these scripts:Caution: you may need to adjust your
.bashrc
so that it doesn't do certain things that only work in a "real" interactive shell session. Don't worry about this unless you get strange errors before rails starts.我假设出现错误是因为 gnome-terminal 尝试运行 Rails 时未设置 PATH。
为什么不使用 Rails 服务器的完整路径,或者创建一个设置 PATH 变量的脚本?
I'm assuming the error arises because PATH is not set at the time gnome-terminal tries to run rails.
Why not use the full path to the rails server, or create a script that sets the PATH variable?
已经回复了,但为了以防万一,请查看这个 gem,它可以在 KDE、OSX 和 Gnome 桌面上自动执行终端。
Already replied, but just in case, check out this gem that automates the terminal on KDE, OSX and Gnome desktops.