Aller au contenu
View in the app

A better way to browse. Learn more.

Next

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[RESOLU] petit shell

Featured Replies

Posté(e)

bonjour

je bosse actuellement sur le codage d'un petit shell, et un probleme me gene: je ne peux pas executer certaines commandes systeme...

certaines commandes passent tres bien, mais il reste des erreures:

pour un ls ou un ls /dev/, il me renvoit un "ls: No such file or directory"

pour un cat ou cat truc.c, j'ai un "ERROR: can't execute /bin/cat" (un de mes messages d'erreur, produit par une mauvaise valeure de retour d'execve)

des idees ?

Modifié par Mephisto

Posté(e)

tu t'en sers comment de ton petit shell ? tu es sûr que le $PATH est bien géré. essaye avec execlp opur voir si ce n'est pas un problème de $PATH vide ou bien trop minial

Posté(e)
  • Auteur

pour le path, je pense que c'est bon, en fait, je recupere dans un char** tous les path, et je fais un boucle pour voire quel cas est le bon, de memoire, ca donne ca :

#include "minishell.h"
#include <stdlib.h>
#include <unistd.h>

void   exec(char **cmd, t_env *env)
{
 char   **path;
 char   *test;

 path = my_strstr(my_getenv("PATH", env->my_environ), ':');
 for (x = 0; path[x]; x++)
{
  if ((test = malloc(sizeof(*test) * my_strlen(path[x]) + my_strlen(cmd[0]) + 2)) == NULL)
	error(jsais plus quel numero d'erreur);
  my_strcpy(test, path[x]);
  my_strcat(test, "/");
  my_strcat(test, cmd[0]);
  if (access(test, X_OK) != -1)
	{
	  run(test, cmd, env->my_environ)
	  break;
	}
  free (test);
}
 if (!(path[x]))
warning(jsais plus quel numero d'erreur);
 free (path);
}

(je viendrai editer quand j'aurai mon code sous la main)

Posté(e)
  • Auteur

le vrai code pour choper le path:

void	choiceexec(char **elem, t_env *env)
{
 int	x;
 char	*test;

 for (x = 0; env->path[x]; x++)
{
  if ((test = malloc(sizeof(*test) * (2 + my_strlen(env->path[x]) +	my_strlen(elem[0])))) == NULL)
	error(0);
  test = my_strcpy(test, env->path[x]);
  test = my_strcat(test, "/");
  test = my_strcat(test, elem[0]);
  if (access(test, X_OK) != -1)
	{
	  free (elem[0]);
	  elem[0] = test;
	  run(elem, env);
	  return;
	}
  free (test);
}
 warning(1);
 my_puterr(elem[0]);
 write(2, "\n", 1);
}

et pour l'execution:

void	run(char **elem, t_env *env)
{
 int   x;
 int   y;

 for (x = 0; elem[x]; x++)
  ;
 if (!(y = (my_strcmp(elem[x - 1], "&")) ? 1 : 0))
elem[x - 1] = 0;
 else if (!(y = (my_cmplastchar(elem[x - 1], "&")) ? 1 : 0))
elem[x - 1][my_strlen(elem[x - 1]) - 1] = 0;
 if (fork() != 0)
{
  if (y)
	wait(0);
}
 else
  if ((execve(elem[0], elem, env->my_environ)) == -1)
  {
warning(2);
my_puterr(elem[0]);
my_puterr("\n");
  }
}

Posté(e)
  • Auteur

c'est regle, grace a -lefence, juste une erreure sur ma mise en tableau des args

et une autre erreur sur mon execve: pour un ls par exemple, on envoit:

execve(cmd, args, environ)

avec cmd = /bin/ls

args[0] = ls

args[1] = 0

voilou

merci quand meme pour ton aide lorinc

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.