Sponsored Content
Full Discussion: HI Newbi in Unix (spanish)
Top Forums Shell Programming and Scripting HI Newbi in Unix (spanish) Post 302349988 by isnhatar on Wednesday 2nd of September 2009 12:47:07 PM
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;
}
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
TRUNCATE(1)							   User Commands						       TRUNCATE(1)

NAME
truncate - shrink or extend the size of a file to the specified size SYNOPSIS
truncate OPTION... FILE... DESCRIPTION
Shrink or extend the size of each FILE to the specified size A FILE argument that does not exist is created. If a FILE is larger than the specified size, the extra data is lost. If a FILE is shorter, it is extended and the extended part (hole) reads as zero bytes. Mandatory arguments to long options are mandatory for short options too. -c, --no-create do not create any files -o, --io-blocks treat SIZE as number of IO blocks instead of bytes -r, --reference=RFILE base size on RFILE -s, --size=SIZE set or adjust the file size by SIZE bytes --help display this help and exit --version output version information and exit The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (pow- ers of 1000). SIZE may also be prefixed by one of the following modifying characters: '+' extend by, '-' reduce by, '<' at most, '>' at least, '/' round down to multiple of, '%' round up to multiple of. AUTHOR
Written by Padraig Brady. REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report truncate translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
dd(1), truncate(2), ftruncate(2) Full documentation at: <http://www.gnu.org/software/coreutils/truncate> or available locally via: info '(coreutils) truncate invocation' GNU coreutils 8.28 January 2018 TRUNCATE(1)
All times are GMT -4. The time now is 03:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy