Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Nov 19, 2018 3:25 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: SSH (Shell) control characters
PostPosted: Thu Mar 15, 2012 7:22 am 
Offline

Joined: Tue Feb 14, 2012 5:39 am
Posts: 99
Location: Austria
Hi!

I got a small (or big) question regarding the shell and SSH in particular.
Basically, i'm using a interactive shell in my application which starts a ssh connection to a machine.
Everything works fine until i want to send a control character like CTRL-C to end a command.

An example would be:

shell.writeLine("tail -f /system/log/system.log")
- some seconds later -
shell.write(Chr(3)) //Chr(3) = CTRL-C

On Windows, everything works fine, the tail command stops and i get my command propmt and i may enter a new command.
But on OSX (both carbon & cocoa) the control character simply doesnt get sent.

Has anyone got any advice for that particular problem? Or maybe a workaround? Because i really need that function for my application and there is no way around that.
That Bug already got reported by Reinhard Blumauer a long time ago, but still is on "reviewed".


Top
 Profile  
Reply with quote  
 Post subject: Re: SSH (Shell) control characters
PostPosted: Fri Mar 16, 2012 2:48 am 
Offline
User avatar

Joined: Fri Oct 28, 2005 7:05 am
Posts: 565
Location: Emsworth, UK
Quote:
Or maybe a workaround? Because i really need that function for my application and there is no way around that.
Well....It is far from elegant and it has issues but..

ssh -qt user@host ps -ef | grep tail | awk '{print $2}' | head -1

...Returns the PID of a tail process on a remote host.

If the PID is 1234...

ssh -qt user@host 'echo "password" | sudo -S kill -s SIGINT 1234'

...Would send a SIGINT to the process, which is the equivalent of typing ctrl-c in an interactive session.

I have tested it in RB as far as making sure it will work when driven manually.

You need to use an interactive shell object, shell.mode=2 to catch the ssh password prompt in .DataAvailable. That might go away if you set up key based login and you might then be able to use a synchronous shell.mode=0.

Logging in as root would remove the need to sudo the kill command and the need to embed the password. Obviously logging in as root raises a lot of other issues and many ssh servers are configured not to allow it.

The gotcha. If there is more than one instance of tail running on the remote host, you need to further filter the output of the ps command to isolate the process that you want to kill.

_________________
Yes it's me in the avatar


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group