Loading ...
Sorry, an error occurred while loading the content.
 

Re: external commands not working

Expand Messages
  • Nils Lohner
    Bram/everyone, I posted this to the main vim list and got no response. Can anyone with a better knowledge of the internals of Vim answer this please?
    Message 1 of 2 , Nov 1, 2000
      Bram/everyone,
      I posted this to the main vim list and got no response. Can anyone with a
      better knowledge of the internals of Vim answer this please?

      Thanks...




      Here's some more information... I think that the programs that get started
      are intended to die when the shell they are spawned from dies as they are
      displays related to that session. The question is (I guess) why the first
      one that I exec manages to stay alive, and then how to make others live in
      the same way.

      THanks,
      Nils.


      In message <200011011630.RAA02877@...>, "Nils Lohner"
      writes:
      >
      >I've got an interesting problem. I'm starting external commands from gvim
      >menus (by hand I get the same problem) as follows:
      >
      >menu IDisplay.temp :e
      >unmenu IDisplay
      >
      >menu IDisplay.Program\ Debug.Immediate :!exec immedwin^M^M
      >menu IDisplay.Program\ Debug.Variables :!exec vardisp^M^M
      >
      >
      >The problem is this: when I first start gvim then I can start exactly _one_
      >program. Any subsequent ones that I start do not start for some reason.
      >Programs such as 'ls' 'echo' etc. are no problem and always work, with and
      >without exec.
      >
      >I've tried without exec and then I get no programs starting. I don't know
      >why not. These programs are all displays designed to be invoked from the
      >command line, meaning they start up and return you to a shell prompt. I
      >think that may be the problem, but have no idea how to track it down or to
      >work around it. I don't know how the startup of these other programs works
      >(no sources) but I'd assume that they exec() or fork() somehow.
      >
      >Any ideas/suggestions? This is in a C shell (tcsh), and bash has the same
      >problem.
      >
      >Ah, more info:
      >:!immedwin;sleep 2
      >:!(immedwin;sleep 2)
      >
      >both of these cause the window to exists for two seconds; then it
      >disappears. So I'd guess that the windows after the first get started but
      >the shell disappears to I never see them. Is there a way to attach them to
      >the shell that gvim was started from?
      >
      >Thanks,
      >Nils.
      >
      >
    • Nils Lohner
      Here s the answer to the puzzle. The programs that started somehow needed to have the controlling terminal around, otherwise they killed themselves off. So,
      Message 2 of 2 , Nov 2, 2000
        Here's the answer to the puzzle.

        The programs that started somehow needed to have the controlling terminal
        around, otherwise they killed themselves off. So, writing a little C
        program to fork another process, set the session ID using setsid() and then
        using a system() call to start the program I wanted worked. I'm not exactly
        sure why this worked but I'll have a closer look at it next week.

        I still don't know why the first display that I started from vim worked and
        the subsequent ones didn't.

        Thanks,
        Nils.

        ps. here's the code...

        #include <stdio.h>
        #include <sys/types.h>
        #include <unistd.h>
        #include <stdlib.h>

        main(int argc, char *argv[], char *envp[])
        {
        pid_t pid;
        char command[256];
        int i, retcode;

        if(argc<=1) exit(0);

        strcpy(command,argv[1]);
        for(i=2;i<argc;i++)
        {
        strcat(command, " ");
        strcat(command,argv[i]);
        }

        pid=fork();

        if(pid==0)
        {
        pid=setsid();
        retcode=system(command);
        }

        if(pid!=0) exit(0);
        }


        In message <200011012350.AAA03073@...>, Nils Lohner
        writes:
        >
        >Here's some more information... I think that the programs that get started
        >are intended to die when the shell they are spawned from dies as they are
        >displays related to that session. The question is (I guess) why the first
        >one that I exec manages to stay alive, and then how to make others live in
        >the same way.
        >
        >THanks,
        >Nils.
        >
        >
        >In message <200011011630.RAA02877@...>, "Nils Lohner"
        >writes:
        >>
        >>I've got an interesting problem. I'm starting external commands from gvim
        >>menus (by hand I get the same problem) as follows:
        >>
        >>menu IDisplay.temp :e
        >>unmenu IDisplay
        >>
        >>menu IDisplay.Program\ Debug.Immediate :!exec immedwin^M^M
        >>menu IDisplay.Program\ Debug.Variables :!exec vardisp^M^M
        >>
        >>
        >>The problem is this: when I first start gvim then I can start exactly _one_
        >>program. Any subsequent ones that I start do not start for some reason.
        >>Programs such as 'ls' 'echo' etc. are no problem and always work, with and
        >>without exec.
        >>
        >>I've tried without exec and then I get no programs starting. I don't know
        >>why not. These programs are all displays designed to be invoked from the
        >>command line, meaning they start up and return you to a shell prompt. I
        >>think that may be the problem, but have no idea how to track it down or to
        >>work around it. I don't know how the startup of these other programs works
        >>(no sources) but I'd assume that they exec() or fork() somehow.
        >>
        >>Any ideas/suggestions? This is in a C shell (tcsh), and bash has the same
        >>problem.
        >>
        >>Ah, more info:
        >>:!immedwin;sleep 2
        >>:!(immedwin;sleep 2)
        >>
        >>both of these cause the window to exists for two seconds; then it
        >>disappears. So I'd guess that the windows after the first get started but
        >>the shell disappears to I never see them. Is there a way to attach them to
        >>the shell that gvim was started from?
        >>
        >>Thanks,
        >>Nils.
        >>
        >>
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.