libmisc/shell
Fernando RUIZ
correo at fernando-ruiz.com
Wed Dec 6 21:54:18 UTC 2006
HI,
You can simulate the shell process and call it.
You can take this code like an idea to do it
#include <???/shell.h>
/* ---------------------------------------------------*/
int set_rawmode(char * devname)
{
ftell(stdin);
ftell(stdout);
ftell(stderr);
stdin =fopen(devname,"r+");
if (!stdin) {
fprintf(stderr,"shell:unable to open
stdin.%s:%s\n",devname,strerror(errno));
return -1;
};
setvbuf(stdin,NULL,_IONBF,0); /* Not buffered*/
/* make a raw terminal,Linux MANuals */
if (tcgetattr (fileno(stdin), &term)>=0) {
term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
term.c_oflag &= ~OPOST;
term.c_oflag |= (OPOST|ONLCR); /* But with cr+nl on output */
term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
term.c_cflag = CLOCAL | CREAD |(shell_env->tcflag);
term.c_cc[VMIN] = 1;
term.c_cc[VTIME] = 0;
if (tcsetattr (fileno(stdin), TCSADRAIN, &term) < 0) {
fprintf(stderr,"shell:cannot set terminal attributes(%s)\n",devname);
};
stdout=fopen(devname,"r+");
if (!stdout) {
fprintf(stderr,"shell:unable to open
stdout.%s:%s\n",devname,strerror(errno));
return -1;
};
setvbuf(stdout,NULL,_IONBF,0); /* Not buffered*/
stderr=fopen(devname,"r+");
if (!stderr) {
fprintf(stdout,"shell:unable to open
stderr.%s:%s\n",devname,strerror(errno));
return -1;
};
};
return 0;
}
/* ---------------------------------------------------*/
int reset_rawmode(char * devname)
{
fclose(stdin);
fclose(stdout);
fclose(stderr);
stdin =fopen(devname,"r+");
if (!stdin) {
return -1;
};
stdout=fopen(devname,"r+");
if (!stdout) {
return -1;
};
stderr=fopen(devname,"r+");
if (!stderr) {
return -1;
};
return 0;
}
/* ---------------------------------------------------*/
int local_shell(char * devname)
{
shell_env_t * shell_env =¤t_shell_env;
shell_cmd_t * shell_cmd;
char cmd[256];
int argc;
char * argv[128];
set_rawmode(devname);
shell_add_cmd(NULL,NULL,NULL,NULL); /* init the chain list*/
register_cmds();
/* add your commands here with shell_add_cmd(...)*/
/* ========= */
/* main loop*/
/* ========= */
for (;;)
{
if (!shell_scanline(cmd,sizeof(cmd),stdin,stdout)) break; /*EOF*/
if (shell_make_args(cmd,&argc,argv)) {
if ((shell_cmd=shell_lookup_cmd(argv[0]))!=NULL) {
shell_env->errorlevel=shell_cmd->command(argc,argv);
} else {
fprintf(stdout,"shell:%s command not found\n",argv[0]);
shell_env->errorlevel=-1;
};
};
/* end exec cmd section */
if (shell_env->exit_shell) break;
cmd[0]=0;
};
/* ========= */
}
reset_rawmode(devname);
return shell_env->errorlevel;
}
/* ---------------------------------------------------*/
See you.
Of course this code is not tested because I don't dispose the rtems box now.
Sorry.
-----Mensaje original-----
De: rtems-users-bounces+correo=fernando-ruiz.com at rtems.org
[mailto:rtems-users-bounces+correo=fernando-ruiz.com at rtems.org]En nombre
de Wolfram Wadepohl
Enviado el: lundi 27 novembre 2006 10:17
Para: rtems-users at rtems.com
Asunto: libmisc/shell
Hello,
is there any further documentation for the shell and the shell environment?
i want to call a shell from and return to caller if user exits.
shell_init() start create and starts another task, but does not wait until
this task terminates. aslo shell_shell() cannot be called because if user
exits the executing task is deleted.
Any suggestions? Thank You.
--
Schöne Grüße aus Reutlingen
Wolfram Wadepohl
Forschung & Entwicklung
E&K AUTOMATION
Indumat GmbH & Co. KG
Siemensstraße 3
72766 Reutlingen
Deutschland
Tel. +49 7121 514-289
Fax +49 7121 514-299
eMail W.Wadepohl at indumat.de
Wolfram.Wadepohl at ek-automation.com
W.Wadepohl at ieee.org
WWW http://www.indumat.de
http://www.ek-automation.com
Bitte senden Sie mir keine Word- oder PowerPoint- (tm Microsoft) Anhänge.
Senden Sie mir einfachen Text, HTML oder PDF.
Siehe http://www.gnu.org/philosophy/no-word-attachments.de.html
More information about the users
mailing list