Xterm and commands

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Xterm and commands

Post by Neo »

I was trying to open a new xterm window and run a command in it (the ls as a test)
I did the following

Code: Select all

xterm -e "ls" &
but all I see is a xterm flashing off really fast.
So does anyone know how to open an xterm and execute a few commands there and keep the new xterm alive still?
Only Human
JoeKayzA

Re:Xterm and commands

Post by JoeKayzA »

The reason why it's gone so fast is that it waits for all sub-processes to finish, and then terminates. "ls" probably finishes _very_ fast, so you only see a short flash...

You could do this instead:

Code: Select all

xterm -e "ls; sh" &
This way the first command will be executed, and then you'll get an interactive shell. When this one is finished then (e.g. you type "exit" in it), xterm will terminate.

I know this is not an elegant solution, but it works. :)

cheers Joe
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Xterm and commands

Post by Neo »

Yup, thanks a lot Joe, that does work. :)
@ all: Is there a more elegant way to do it or is that the only way?
Only Human
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Xterm and commands

Post by Neo »

I wanted to run a script to log me into another machine and then use the xterm, but after the bash shell appears I have to type in the script name to continue.
Is there any way to do this?
Only Human
JoeKayzA

Re:Xterm and commands

Post by JoeKayzA »

Well, that's because as soon as execution reaches the "sh", it blocks and waits for input from the user. Assuming you do the following now:

Code: Select all

xterm -e "[scriptname]; sh" &
it would mean you wait for the script to terminate and then open a _local_ shell. I suspect you'll have to modify the script that it doesn't terminate and instead waits for your input. What does it look like?

cheers Joe
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Xterm and commands

Post by Neo »

Thanks a lot it works now. I modified the script to get input at the end at it works. :)
Only Human
Post Reply