HI Newbi in Unix (spanish)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HI Newbi in Unix (spanish)
# 1  
Old 09-02-2009
HI Newbi in Unix (spanish)

Mi idea es crear un pequeña shell...lo que pasa es que cuando ejecuto el siguiente programa va todo bien hasta que me salta el error
perror("Error al ejecutar la función execvp\n");
Entonces la aplicación me entra en un bucle(repitiendo todo el rato el error anterio), como puedo hacer para que eso no pase.

#include <iostream>
#include <unistd.h>
#include <cstring>
#include <sys/wait.h>

using namespace std;

const int MAX_ELEMENTOS=12; //De esta manera limitamos un numero maximo de "comandos", en este caso lo limitamos a 12.

void trocear_linea(char *, char *[]); //Utilizaremos esta funcion para dividir la linea de comandos que nosotros le metemos.

int main()
{
char cadena[100];
char *lista_elementos[MAX_ELEMENTOS];

pid_t pid; //Declaramos la variable pid.

cout<<"PROMPT-MI-SHELL: "; //Este es el mensaje que aparecera al ejecutar el programa, es decir el prompt.
cin.getline(cadena,100); //Leemos el prompt, y lo introducimos en la cadena que luego trocearemos.

trocear_linea(cadena,lista_elementos); //Troceamos la linea de comandos que previamente le hemos introducido.

while (strcmp(lista_elementos[0],"salir")!=0)
{
pid=fork(); //Creamos un proceso hijo.

if(pid==0) //Evaluamos el pid del hijo y entonces ejecutamos el comando.
{
if (execvp(lista_elementos[0], lista_elementos)==-1)
{
perror("Error al ejecutar la funcion execvp\n"); //Este error aparecerá cuando introduzcamos comandos erroneos.

}
}
else
{
wait(NULL); //Si el pid es el del padre, este esperará hasta que termine el proceso hijo.
cout<<"PROMPT-MI-SHELL: "; //Este es el mensaje que aparecera al ejecutar el programa, es decir el prompt.
cin.getline(cadena,100); //Leemos el prompt, y lo introducimos en la cadena que luego trocearemos.

trocear_linea(cadena,lista_elementos); //Troceamos la linea de comandos que previamente le hemos introducido.

}


}

cout<<"El programa ha terminado";

}

void trocear_linea(char *linea, char *lista_elementos[])
{
char *elemento;
const char DELIMITADOR[]=" \t"; //Espacio en blanco o tabulador.
int num; //Número de elementos.

num=0;
while (linea!=NULL && num<MAX_ELEMENTOS)
{
elemento=strsep(&linea,DELIMITADOR);
if (strcmp(elemento,"")!=0)
{
lista_elementos[num]=elemento;
num++;
}
}
lista_elementos[num]=NULL;
}
# 2  
Old 09-02-2009
Hello.

Per our forum rules, all posts must be in English.

We do provide translation services for posts from English to a number of languages as a benefit to users. However, posts must be in English.

Please repost in English.

Thank you for your cooperation.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. What is on Your Mind?

Spanish Speaking Forum Members?

Hi! Any Spanish speaking forum members? If so, please reply! Thanks! (2 Replies)
Discussion started by: Neo
2 Replies

2. Shell Programming and Scripting

Spanish Shell script

Question,Anyone I found a script on github that I like it executes find but every word on the screen is in spainish ...other than learning Spanish...is there language translating software that will work on bash shell script to change it to English..?? large file has 4500 lines of code 254kb:wall:... (1 Reply)
Discussion started by: bmark109
1 Replies

3. SuSE

Newbi: High availbilty extenstion for SLES 11 on VMware

Hi Guys , Can some one help me out with the basic requirements and steps required to setting up High availabilty extension in SLES11 sp2 on vmware .:) Iam struggling with the basic installation of SLES and finally completed it after a long trilas and it will be helpful if some one do help me... (0 Replies)
Discussion started by: shiek.kaleem
0 Replies

4. Red Hat

Spanish Characters get converted in strange chrac

I am trying to sftp a textfile from windows to linux. The file includes some spanish characters. When I vi the file in LINUX, the special (spanish) characters get converted into some strange characters. anyone know how i can resolve this? for example México gets converted into México on LINUX. (0 Replies)
Discussion started by: mrx1350
0 Replies

5. Shell Programming and Scripting

Remove spanish accent from file name

Hello All hope all fine, I have a question about spanish accents... I have in a redhat server, a lot of files with Ñ or Ú accent into the NAME of the file. So my question is: Is it possible to change this name but with a script...to change all the occurence in one shot. Exemple: cd... (2 Replies)
Discussion started by: ldiaz2106
2 Replies

6. Shell Programming and Scripting

Spanish accent symbol removed by sed

Hello All in a text file I have to replace some numeric code by a string. This is an exemple of the file: 000000001 LDR L ^^^^^nam^^2200169Ia^45e0 000000001 008 L 100604s9999^^^^xx^^^^^^^^^^^^000^0^und^d 000000001 022 L $$a0365-6675 000000001 090 L $$aBMA 1934-1937. 000000001 245... (1 Reply)
Discussion started by: ldiaz2106
1 Replies

7. UNIX for Dummies Questions & Answers

Keyboard/Spanish

I am looking for information to find out the easiest way to have my keyboard be able to do Spanish punctuation marks when typing in word processing in Open Office....... (0 Replies)
Discussion started by: scuup
0 Replies

8. UNIX for Dummies Questions & Answers

viewing spanish file in vi editor

hi, I have a file in unix which contains spanish entries When I try to open the file in vi editor i can see some spaces as shown below when I ftp the same file and see in my machine i can see it clearly what settings i can use while viewing the file in vi plz find some snapshot of the... (1 Reply)
Discussion started by: trichyselva
1 Replies

9. UNIX for Dummies Questions & Answers

Newbi - Understanding the Code and proper download

Hi, I am new to Unix and there is code that is trying to get data from a location and save it. However it's output is messing up some date fields in the source file (ie... in source is may say 10/10/2008, the code will output 10/10/20088). This is the piece of code. Can someone help to... (2 Replies)
Discussion started by: mpinto
2 Replies
Login or Register to Ask a Question