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

Re: Running another exe program from Main Perl program without interupting

Expand Messages
  • Alexander Saydakov
    ... In other words, you want to fork off a child process. perldoc -f fork perldoc perlfork /sandy http://myperlquiz.com/
    Message 1 of 6 , Mar 16, 2008
      --- In perl-beginner@yahoogroups.com, "joshypy" <joshypy@...> wrote:
      > I would like to run another (.exe) program from my perl main program
      > without any interrupting my main program.
      >
      > Right now I am using
      >
      > system("newprogram.exe");
      >
      > But for this my main program is waiting for the new program to get
      > closed. I still want my main program to continue while the
      > "newprogram.exe" is running.

      In other words, you want to fork off a child process.

      perldoc -f fork
      perldoc perlfork

      /sandy
      http://myperlquiz.com/
    • joshypy
      Thanks Sandy, Its working for me. But I am struggling to kill the child process later from the main program. The following is the code I used: $| = 1; if ($pid
      Message 2 of 6 , Mar 16, 2008
        Thanks Sandy, Its working for me. But I am struggling to kill the
        child process later from the main program. The following is the code I
        used:

        $| = 1;

        if ($pid = fork) {
        print "End of Parent";
        $child_pid=$pid;
        } else {

        system ("newprogram.exe");
        exit(0);
        }

        #Here I want to close the "newprogram.exe"
        kill ($child_pid);


        But the Killing is not working.

        Thanks

        Joshy



        --- In perl-beginner@yahoogroups.com, "Alexander Saydakov"
        <sandy_saydakov@...> wrote:
        >
        > --- In perl-beginner@yahoogroups.com, "joshypy" <joshypy@> wrote:
        > > I would like to run another (.exe) program from my perl main program
        > > without any interrupting my main program.
        > >
        > > Right now I am using
        > >
        > > system("newprogram.exe");
        > >
        > > But for this my main program is waiting for the new program to get
        > > closed. I still want my main program to continue while the
        > > "newprogram.exe" is running.
        >
        > In other words, you want to fork off a child process.
        >
        > perldoc -f fork
        > perldoc perlfork
        >
        > /sandy
        > http://myperlquiz.com/
        >
      • Jenda Krynicky
        From: joshypy ... system( 1, newprogram.exe ); From perldoc perlport As an optimization, may not call the command shell
        Message 3 of 6 , Mar 17, 2008
          From: "joshypy" <joshypy@...>
          > I would like to run another (.exe) program from my perl main program
          > without any interrupting my main program.
          >
          > Right now I am using
          >
          > system("newprogram.exe");
          >
          > But for this my main program is waiting for the new program to get
          > closed. I still want my main program to continue while the
          > "newprogram.exe" is running.


          system( 1, "newprogram.exe");

          From
          perldoc perlport

          As an optimization, may not call the command shell specified in
          $ENV{PERL5SHELL}. system(1, @args) spawns an external process and
          immediately returns its process designator, without waiting for it to
          terminate. Return value may be used subsequently in wait or waitpid.
          Failure to spawn() a subprocess is indicated by setting $? to "255 <<
          8". $? is set in a way compatible with Unix (i.e. the exitstatus of
          the subprocess is obtained by "$? >> 8", as described in the
          documentation). (Win32)


          If you need more control have a look at Win32::Process.

          HTH, Jenda
          ===== Jenda@... === http://Jenda.Krynicky.cz =====
          When it comes to wine, women and song, wizards are allowed
          to get drunk and croon as much as they like.
          -- Terry Pratchett in Sourcery
        • Alexander Saydakov
          ... I would try calling exec() instead of system() here. system() introduces one more level of parent-child, which is an unnecessary complexity here. ... I am
          Message 4 of 6 , Mar 17, 2008
            --- In perl-beginner@yahoogroups.com, "joshypy" <joshypy@...> wrote:
            >
            > Thanks Sandy, Its working for me. But I am struggling to kill the
            > child process later from the main program. The following is the code I
            > used:
            >
            > $| = 1;
            >
            > if ($pid = fork) {
            > print "End of Parent";
            > $child_pid=$pid;
            > } else {
            >
            > system ("newprogram.exe");
            > exit(0);

            I would try calling exec() instead of system() here. system()
            introduces one more level of parent-child, which is an unnecessary
            complexity here.

            > }
            >
            > #Here I want to close the "newprogram.exe"
            > kill ($child_pid);

            I am not sure why do you want to kill it. You want the parent and the
            child to do something in parallel, don't you? And when the parent is
            done, you probably want it to wait for the child.

            perldoc -f wait
            perldoc -f waitpid

            /sandy
            http://myperlquiz.com/
          • joshypy
            Thanks Sandy and Jenda, It s working for me. I liked the Win32:: Process , since it is giving more control Thanks Joshy
            Message 5 of 6 , Mar 18, 2008
              Thanks Sandy and Jenda,

              It's working for me.

              I liked the Win32:: Process , since it is giving more control

              Thanks

              Joshy

              --- In perl-beginner@yahoogroups.com, "Jenda Krynicky" <Jenda@...> wrote:
              >
              > From: "joshypy" <joshypy@...>
              > > I would like to run another (.exe) program from my perl main program
              > > without any interrupting my main program.
              > >
              > > Right now I am using
              > >
              > > system("newprogram.exe");
              > >
              > > But for this my main program is waiting for the new program to get
              > > closed. I still want my main program to continue while the
              > > "newprogram.exe" is running.
              >
              >
              > system( 1, "newprogram.exe");
              >
              > From
              > perldoc perlport
              >
              > As an optimization, may not call the command shell specified in
              > $ENV{PERL5SHELL}. system(1, @args) spawns an external process and
              > immediately returns its process designator, without waiting for it to
              > terminate. Return value may be used subsequently in wait or waitpid.
              > Failure to spawn() a subprocess is indicated by setting $? to "255 <<
              > 8". $? is set in a way compatible with Unix (i.e. the exitstatus of
              > the subprocess is obtained by "$? >> 8", as described in the
              > documentation). (Win32)
              >
              >
              > If you need more control have a look at Win32::Process.
              >
              > HTH, Jenda
              > ===== Jenda@... === http://Jenda.Krynicky.cz =====
              > When it comes to wine, women and song, wizards are allowed
              > to get drunk and croon as much as they like.
              > -- Terry Pratchett in Sourcery
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.