nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] Patch to execute external command and inerst output int


From: Dwayne Rightler
Subject: Re: [Nano-devel] Patch to execute external command and inerst output into buffer...
Date: Thu, 21 Mar 2002 18:49:52 -0600 (CST)

Clean...  I was looking for a better way to do pipes, now I see how  :)



On Thu, 21 Mar 2002, Chris Allegretta wrote:

> On Thu, Mar 21, 2002 at 12:55:50AM -0600, Dwayne Rightler wrote:
> >
> > Now I am having trouble reproducing the segfault...  it happened for me
> > twice and now it doesnt... heh....  Anyway here is a patch which fixes the
> > ugly stderr output...
>
> Hi Dwayne,
>
>       I just hacked this together and committed it to CVS, but what do
> you think:
>
> #ifndef NANO_SMALL
> int open_pipe(char *command)
> {
>     int fd[2], pid;
>
>   /* Make our pipes. */
>
>     if (pipe(fd) == -1) {
>       statusbar("Could not pipe");
>       return 1;
>     }
>
>     /* Fork a child */
>
>     if ((pid = fork()) == 0) {
>       close(fd[0]);
>       dup2(fd[1], fileno(stdout));
>       dup2(fd[1], fileno(stderr));
>       /* If execl() returns at all, there was an error. */
>
>       execl("/bin/sh","/bin/sh","-c",command,0);
>       exit(0);
>     }
>     else if (pid == -1) {
>       statusbar(_("Could not fork"));
>       return 1;
>     }
>
>     /* Else continue as parent */
>     close(fd[1]);
>     read_file(fd[0],"stdin",0);
>     set_modified();
>     return 0;
> }
> #endif /* NANO_SMALL */
>
> Chris A
> --
> Chris Allegretta      http://www.asty.org
>
> "Share and Enjoy" - Douglas Adams, 1952 - 2001
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]