New User? Register here - Existing Users: Username: Password: [Advanced Login]

 

 

Current Poll

What language for system administration do you use ?







( 731 votes ~ 3 comments )

 

Weblog entry #58 for Utumno

inject a command to a terminal
Posted by Utumno on Mon 17 Jan 2011 at 09:26
Tags: none.

Hello Debian gurus,

I've got a Linux-based gizmo. There is a process running there; it is connected to (serial) terminal /dev/ttyS0.

I can connect to the terminal ( as root ) ,issue commends and control the process. Now I would like to make the process be remotely-controlled, i.e. I would like to write a program that

1) listens on some ip port
2) passes on all commands it gets to the process I want to control

I know how to do 1), but I have no idea how to do 2). Any ideas?

I cannot modify the process in question, all I can do is somehow try to inject a command to its controlling terminal. But simple attempts like 'echo abcd > /dev/ttyS0' do not seem to work - the 'abcd' gets sent to the process I want to control, but does not get executed by it, because the ending 'ENTER' does not seem to get passed.

 

Comments on this Entry

Posted by Utumno (203.160.xx.xx) on Mon 17 Jan 2011 at 10:37
[ Send Message | View Utumno's Scratchpad | View Weblogs ]
ok, I got it.

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>

int main(void)
{
int hTTY = open("/dev/tty1", O_WRONLY|O_NONBLOCK);
ioctl(hTTY, TIOCSTI, "p");
ioctl(hTTY, TIOCSTI, "\n");
close(hTTY);
return 0;
}

[ Parent | Reply to this comment ]

 

 

Flattr