How to Launch Multiple Xterm Windows and Run a Command on Each, Leaving Each Window Open Afterward

How can I launch multiple xterm windows and run a command on each, leaving each window open afterward?

I'd love to see a more elegant answer, but what I came up with does work:

xterm -e bash -c 'echo foo; exec bash'

Replace echo foo with the command of your choice, and you're good to go.

open several xterm windows from script without closing

Assuming that you want to see what the command produced even if it failed, replace your commands with:

xterm -xrm '*hold: true' -e $1 &   # this is to keep xterm from closing
pid1=$! # this is to save the pid, in case you want to close it
disown # this is to prevent the finishing shell from closing the xterm

Alternatively, if the xterm does not support -xrm option:

CMD="$1" xterm -e $SHELL -c '$SHELL -c "$CMD"; read'

The two shells are to protect from syntax errors in the command, to keep the xterm open even in this case.

spawn a new xterm window

You're going to need an Xwindows server on your Windows box in order to run graphical Unix apps remotely on the Sun server and have it display on your Windows box. I don't think Tunnelier supports Xwindows tunneling. Take a look at Xming, an Xwindows server for Windows that comes with Putty, an ssh client:

http://sourceforge.net/projects/xming

edit: Glad to see this worked for you. Here's some more explanation on what's happening. X-Windows, the Unix graphical environment is client-server based. IE: it's able to display individual graphical windows on remote systems without full-screen software like VNC or remote desktop. A graphical program in Unix is called the X-Windows client, and the thing that actually does the displaying is called an X-Windows server.

Now, Bitvise Tunnelier is just an ssh client. IE: it only deals with command-line terminal connections. However, the ssh protocol is actually able to tunnel X-Windows over ssh, but you need two things: 1) an X-Windows server running on your desktop (to actually display the app), and 2) an ssh client that supports X-Windows tunneling. Enter Xming, a lightweight X server for windows, and Putty, the ssh client.

So, you were fine ssh-ing in to your Sun box, and typing terminal commands, but Visual SlickEdit is an X-Windows client app. To run that, you needed an X-Windows server. When an X-Windows server is available, it sets the DISPLAY variable on the terminal to tell graphical apps where to display stuff.

One more note: Some of the answers below recommended that you set the DISPLAY variable to the hostname of your Sun box. That might have worked, but it would have displayed the VS windows on the Sun's screen, not your Windows box.

How to write a shell script to open four terminals and execute a command in each?

You could use a "for" loop, and a "&" to run xterm in background:


#!/bin/bash

# some older test, doesn't work and complains and I get this message on command line: "QApplication::qAppName: Please instantiate the QApplication object first"
# I also can't enter text after command executes
#echo "Hello World!"
#exec konsole --noclose -e cat ~/.aliases

for i in 1 2 3 4
do
# opens terminal but then I can't control terminal afterwards
xterm -hold -e "echo Hello My World" &
done

# didn't do anything
#exit 0

# didn't do anything except make me type exit an extra time where I executed my shell script
#$SHELL


Related Topics



Leave a reply



Submit