14

I have an automated test that I run with the xterm -e command:

xterm -e  RunMyTests

At the end of the test-run, it prints out a summary of the results and some statistics to stdout.

I'd like to have the xterm remain open and visible so I can check the results.
(if its inactive, that's fine, so long as I can see it)

I know I could manually start the xterm then run the tests there.
Or I could redirect the test-output to a file to be examined later.
Or I could run the tests in the current xterm, instead of spawning a new window.
All of these could work, but are not ideal.

Is there a way to get an xterm window to stay open after its completed its work?

abelenky
  • 963
  • 2
  • 11
  • 23
  • The problems is that there is no shell running in the xterm for it to go back to when the tests are done. I imagine there is a way to get bash to execute RunMyTests and remain open afterwards, but I can't find it off hand. Hrm. – user606723 Dec 01 '11 at 19:47
  • I don't even care if anything remains running. I just want the window to stay visible (and eventually close when I hit the 'X' button) – abelenky Dec 01 '11 at 19:49
  • There has to be something running or the terminal will close. I am pretty sure thats just how it works. – user606723 Dec 01 '11 at 19:52
  • The command you are trying to execute doesn't make much sense: it will start a shell under the user `user2`, and then after the user quits that shell, it will uselessly source a `.cshrc` file before exiting. Did you mean so source that file inside `user2`'s shell instead? – Celada Jun 12 '13 at 18:10
  • Yes, I am trying to source user's .cshrc under the new user2 window. I realize the syntax might be off by a little which is why I am not able to figure it out. Thanks. –  Jun 12 '13 at 20:18
  • You might consider changing the accepted answer, as @AndresVia's solution is simpler and more elegant. – Reid Sep 09 '14 at 21:23
  • @Reid: You seriously want me to revisit a question that got a better answer 6 months later, when the whole topic is nearly 3 years old? I don't disagree that its a very good answer, but I'm not continuously monitoring old questions to see if better answers have come up. – abelenky Sep 09 '14 at 21:27
  • Yes, and there's no need to get bent out of shape about it. No one expects you to monitor old questions. That's why I left you a comment pointing out it was here. – Reid Sep 09 '14 at 21:56

3 Answers3

39

From xterm(1):

   -hold   Turn on the hold resource, i.e.,  xterm  will  not  immediately
           destroy  its  window when the shell command completes.  It will
           wait until you use the window manager to destroy/kill the  win‐
           dow,  or  if you use the menu entries that send a signal, e.g.,
           HUP or KILL.

Standard command: xterm -hold "echo I'm a boy"

Gambas Code: exec["xterm", "-hold", "-e", "ps aux"

Jon
  • 9,181
  • 39
  • 95
  • 127
AndresVia
  • 491
  • 1
  • 4
  • 4
  • 2
    The name of the option is not intuitive when searching through the man page. This is the right answer, less typing, using the features like a Superuser should. – Tomasz Gandor Mar 10 '16 at 13:48
  • As usual, on a Mac, this sort of works. At least under XQuartz, the terminal stays around, but there does not appear to be a way to kill the window other than exiting XQuartz. In particular, the red dot that kills most windows does not kill the xterm window. – Troy Daniels Jan 25 '22 at 18:08
13

The problem is that there is no shell running in the xterm for it to go back to when the tests are done.

Try this.

xterm -e "echo hi;bash"

Or

xterm -e "echo hi;read"
user606723
  • 1,441
  • 2
  • 14
  • 19
1

In the case were you would normally open a terminal and then source an environment script and then continue with other commands, I found the following to work where an lxterminal is all that is available.

lxterminal -e bash -c "< path to env script \> bash --noprofile"

For instance:

lxterminal -e bash -c "/home/pi/linuxcnc-dev/scripts/rip-environment bash --noprofile"

This creates a terminal window executing bash that sources an environment script to run bash that does not overwrite the sourced environment. In the end, it's leaving the terminal open with the sourced environment, which answers the question. If you remove the first -e bash, the lxterminal hangs with no prompt.

zx485
  • 2,170
  • 11
  • 17
  • 24
ztalbot
  • 51
  • 3