예제 #1
0
파일: minitools.c 프로젝트: jalcim/42sh
int			exec_cmd(t_sh *t)
{
	int		i;
	int		j;
	char	*str;

	i = -1;
	j = -1;
	str = ft_strnew(0);;
	t->tmp = NULL;
	t->fo = 0;
	if (!t->args[0])
		return (1);
	while (t->args[++j])
		if (!my_regex(t->args[j], "#-_A~Z0~9a~z\\=\\#-_A~Za~z./0~9*?", 0, '\0'))
			break ;
	if (t->args[j])
	{
		j = 0;
		str = ft_strdup(t->args[0]);
		ft_strdel(&t->args[0]);
		while (t->args[++j])
			str = ft_strjoin_free(str, ft_strjoin_free(" ", t->args[j], 2), 3);
		free(t->args);
		t->args = ft_strsplit(set_local_var(&str, 0, t), ' ');
		return (0);
	}
	if (ft_strchr(t->args[0], '='))
	{
		ft_putendl_fd("Bad variable format", 2);
		return (-1);
	}
	exec_cmd1(t, &i);
	return (exec_cmd2(t, &i));
}
예제 #2
0
파일: pipex.c 프로젝트: vrebierr/pipex
int		main(int argc, char **argv, char **envp)
{
	int		fd[2];
	int		pipe_fd[2];
	pid_t	pid;

	if (argc != 5)
		return (show_error("Usage: ./pipex file1 cmd1 cmd2 file2"));
	if (pipe(pipe_fd) == -1)
		return (show_error("pipex: fail"));
	if ((fd[0] = open(argv[1], O_RDONLY)) == -1)
		return (show_error("open file1: fail"));
	if ((fd[1] = open(argv[4], O_WRONLY | O_CREAT, 0777)) == -1)
		return (show_error("open file2: fail"));
	if ((pid = fork()) < 0)
		return (show_error("fork: fail"));
	if (pid == 0)
		exec_cmd(argv[2], fd, pipe_fd, envp);
	else
		exec_cmd2(argv[3], fd, pipe_fd, envp);
	close(fd[0]);
	close(fd[1]);
	return (0);
}