3

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?

medihack
  • 16,045
  • 21
  • 90
  • 134

4 Answers4

16

Here is a nice trick we worked out at Superuser

  1. Add a eval "$BASH_POST_RC" to the end of your .bashrc

  2. 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!

Community
  • 1
  • 1
medihack
  • 16,045
  • 21
  • 90
  • 134
  • Try `-e 'env BASH_POST_RC=\"rails server\" bash'` for a shorter version. Do same thing for the second `--tab -e` argument. – Henk Langeveld Oct 10 '14 at 16:03
  • I had a similar problem and tried your technique. It worked. Thank You. I did notice that the comnmand string doesn't get put in the terminal or the history. Is there a way to do that? – Steve Dec 31 '14 at 05:10
  • I tried a few minutes of Googling. What does the variable BASH_POST_RC mean? – Steve Dec 31 '14 at 05:11
1

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

#! /bin/sh
exec rails server

chmod +x it, and then do

gnome-terminal --tab -e /home/zardoz/bin/railsstart --tab --tab ...

If 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 through trace.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:

#! /bin/bash
. ~/.bashrc
exec rails server

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.

zwol
  • 135,547
  • 38
  • 252
  • 361
  • That approach has the same flaws as my second gnome-terminal statement. It really tries to run "rails server" in that tab, but doesn't succeed cause it can't find the command "rails". That command is only present when the .bashrc was correctly called before execution. And that is not the case when executing commands by using gnome-terminal -e. – medihack Oct 09 '10 at 19:09
  • Try having the wrapper script run your `.bashrc`, then - see edit. – zwol Oct 10 '10 at 18:42
0

Already replied, but just in case, check out this gem that automates the terminal on KDE, OSX and Gnome desktops.

Achilles
  • 766
  • 4
  • 13
0

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?

salezica
  • 74,081
  • 25
  • 105
  • 166
  • There are some further problems. I use RVM to setup the whole Ruby environment. And RVM is setup in the .bashrc. So I have to make sure that gnome-terminal -e "command" at first executes the .bashrc and then the command. – medihack Oct 10 '10 at 10:14
  • I don't think I'm understanding your problem =/ You can have gnome-terminal execute more than one command, in a specified order. Probably separating the commands with ; will work, and you can use -x to execute the rest of the line if not. Am I getting something wrong? – salezica Oct 10 '10 at 22:58