Re: Redirection issue




Bo Yang wrote:

int
redir_cmd(char *argv[],char *in, char *out)
{
int i;
int pid, status;
int fd1, fd2;
int dummy;

if (strcmp(argv[0],"exit")==0)
return do_exit(argv);
for(i=0;argv[i]!=NULL;i++)
printf("argv[%i]=\"%s\";\n",i,argv[i]);

if (strcmp(argv[0],"cd")==0)
{
return chdir(*argv);
}

if (fork() == 0) {
fd1 = open(in, O_RDONLY);
if (fd1 < 0) {
perror("can't open file : in");
exit(1);
}

if (dup2(fd1, out) != 0) {
You dup the out to fd1 , but out is a char pointer ,
what do you want to do ?
This must to be failed .

You can just dup the stdin to in , and dup stdout to out .

Hi Bo,

I have changed the fd1 and fd2 types and the redirection is now
working. The shell compiles . The commands of the input file
(input.txt) have been executed and the output is sent to the outout
file (ouput.txt).
Now, I have another issues in the sens that the simple command and the
commands passed in a file are not executed.
In the main function I have treated 3 cases : simple command, input
file, and redirection. But the problem may be in the rediretion
(redirect_cmd) function.

Any idea please.

Thanks,

Souissipro

.



Relevant Pages

  • Re: [PATCH] Prevent NMI oopser
    ... -static inline void ... * commands. ... -static inline int ... +static inline scb_t * ...
    (Linux-Kernel)
  • Sockets Redirection problem
    ... I am trying to build a simple server that can execute local commands ... executing ls, cd, find and all of the normal unix utility programs. ... int execute; ...
    (comp.os.linux.development.apps)
  • [patch 2/3] s390: add vmcp interface.
    ... Add interface to issue VM control program commands. ... * the caller of __cpcmd has to ensure that the response buffer is below 2 GB ... +static int vmcp_open ...
    (Linux-Kernel)
  • Re: Reintroducing fish, the friendly interactive shell
    ... Kurt Swanson skrev: ... the writers of all the commands to implement this would be infeasible. ... specific switch, in which case val and flag must also be 0. ... int has_arg; ...
    (comp.unix.shell)
  • Re: Re: i686 hang on boot in userspace
    ... afterwards I will try to bisect the revisions you mentioned. ... int i, ddir; ... /* We have room on the queue for more commands. ...
    (Linux-Kernel)