|
Home > Archive > Unix Programming > May 2007 > xterm and press enter
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
xterm and press enter
|
|
|
| hi all:
I'm fork a xterm(child process) and try to write the pseudo
terminal pts.
I'm confused when I try to write the pts in the parent process, I have
to press the enter in the xterm and the data I try to write on the pts
show on the xterm. But my want is to show the data on the xterm as I
write data in the pts (without press any key).
what can I do?
Dave.
The following source code is the way I initial the pseudo terminal and
fork the xterm.
366 int init_VHyper_terminal(int* pts_master,
367 int* pts_slave
368 ){
369
370 //open a psudo terminal ptmx, following steps just obey the web
site orderings!XD
371 if ((*pts_master = open("/dev/ptmx", O_RDWR)) == -1) return(-1);
372
373 if (grantpt(*pts_master)) {
374 close(*pts_master);
375 return(-1);
376 }
377 if (unlockpt(*pts_master)) {
378 close(*pts_master);
379 return(-1);
380 }
381
382 //got the pts_slave's name!!!
383 if ((pts_slave_name = (char *)ptsname(*pts_master)) == NULL) {
384 close(*pts_master);
385 return(-1);
386 }
387
388 if ((*pts_slave = open(pts_slave_name, O_RDWR)) == -1) {
389 return(-1);
390 }
391 {
392 struct termios new_termios;
393 if (tcgetattr(*pts_slave, &pts_slave_termios)) {
394 return -1;
395 }
396 new_termios = pts_slave_termios;
397
398 new_termios.c_lflag &= (ECHO|ECHOE|ECHOK|ECHONL);
399 new_termios.c_lflag &= FLUSHO;
400
401
402 new_termios.c_oflag &= OCRNL;
403 new_termios.c_oflag &= CRDLY;
404
405
406 new_termios.c_iflag &= IGNCR;
407 new_termios.c_iflag &= ~ICRNL;
408 new_termios.c_iflag &= INLCR;
409
410
411
412 if (tcsetattr(*pts_slave, TCSADRAIN, &new_termios)) {
413 return -1;
414 }
415 }
416 }
....
426 int VHyperTerminal() {
427 pid_t pid;
428 pid_t pid2;
429 int pts_master;
430 int pts_slave;
431 // char* pts_slave_name = NULL;
432
433 init_VHyper_terminal(&pts_master, &pts_slave);
434
435
436 if ((pid = fork()) == -1) {
437 perror("fork error\n");
438 return -1;
439 }
440
441
442 if (pid == 0) {
443 close(pts_slave);
444 char S_arg[80];
445
446 char pts_slave_dev_c =
pts_slave_name[strlen(pts_slave_name)-2];
447 if(pts_slave_dev_c == '/'){
448 sprintf(S_arg, "-S%c/%d ",
pts_slave_name[strlen(pts_slave_name)-1], pts_master);
449 }else if((pts_slave_dev_c =
pts_slave_name[strlen(pts_slave_name)-3])== '/'){
450 sprintf(S_arg, "-S%c%c/
%d",pts_slave_name[strlen(pts_slave_name)-2],pts_slave_name[strlen(pts_slave_name)-1],pts_master);
451 }
452 const char xterm[]=XTERM_PATH;
453 execl(xterm, xterm, S_arg, 0);
454 return -1;
455 }
456
457 close(pts_master);
458
459 while (1) {
460 int nbytes;
461 char c;
462 nbytes = read(pts_slave, &c, 1);
463 if (nbytes == -1 || nbytes == 0) {
464 return -1;
465 }
466 if (c == '\n')
467 break;
468 }
469
470 if (tcsetattr(pts_slave, TCSADRAIN, &pts_slave_termios)) {
471 return -1;
472 }
473
474 read_VH = dup(pts_slave);
475 write_VH = dup(pts_slave);
476 close(pts_slave);
477 Rx_pt = Rx_buf;
478 read_Rx_pt = Rx_pt;
| |
| Stephane CHAZELAS 2007-05-01, 7:28 pm |
| 2007-05-1, 09:18(-07), Dave:
> hi all:
> I'm fork a xterm(child process) and try to write the pseudo
> terminal pts.
> I'm confused when I try to write the pts in the parent process, I have
> to press the enter in the xterm and the data I try to write on the pts
> show on the xterm. But my want is to show the data on the xterm as I
> write data in the pts (without press any key).
> what can I do?
[...]
Try and clearing ICANON in the c_lflags and set VMIN to 1 and
VTIME to 0 on the pty slave.
What you're seeing I think is the canonical mode in action, in
which the data written to the slave side is only made available
to the master side when a (non lnext'ed) CR or NL (depending on
the ICRNL, INLCR... settings) character has been written.
--
Stéphane
| |
|
| On Tue, 01 May 2007 09:18:22 -0700, Dave wrote:
> hi all:
> I'm fork a xterm(child process) and try to write the pseudo
> terminal pts.
> I'm confused when I try to write the pts in the parent process, I have
> to press the enter in the xterm and the data I try to write on the pts
> show on the xterm. But my want is to show the data on the xterm as I
> write data in the pts (without press any key).
> what can I do?
>
> Dave.
>
> 391 {
> 392 struct termios new_termios;
> 393 if (tcgetattr(*pts_slave, &pts_slave_termios)) {
> 394 return -1;
> 395 }
> 396 new_termios = pts_slave_termios;
> 397
> 398 new_termios.c_lflag &= (ECHO|ECHOE|ECHOK|ECHONL);
> 399 new_termios.c_lflag &= FLUSHO;
This makes no sense. You are probably confusing some |= and &= , or you
missed a few ~ s.
I did not read the rest.
HTH,
AvK
|
|
|
|
|