http://www.perlmonks.org?node_id=11132792


in reply to Killing subprocess in windows

Hello LanX,

instead of your unusual syntax, you can try to fork (anyway system does fork under the hood) so that you'll have back the PID?

You can also use Win32::Process to create and kill the subprocess.

As you just need to tail a file you can try other simpler ways: is File::Tail usable on Windows ? tail and grep for Windows

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Killing subprocess in windows
by LanX (Sage) on May 20, 2021 at 21:36 UTC
    > instead of your unusual syntax, you can try to fork

    could you please show me how? From the docs:

    fork() creates a new process by duplicating the calling process.

    I don't wanna replicate the Perl script but spawn a PS window.

    > tail and grep for Windows

    does this offer the -f option? I don't think so.

    > is File::Tail usable on Windows ?

    File::Tail seems overkill, and like the title suggests there might be problems on Win

    get-content -wait is a built-in in all modern Win versions

    > You can also use Win32::Process to create and kill the subprocess.

    That's a very good idea, thanks! :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

        Yes, i know you don’t want to spawn…

        But consider something like this:

        use strict; use warnings; use threads; use MCE::Hobo; my $hobo = MCE::Hobo->create( sub { …; }); my $pid = $hobo->pid(); # $hobo->join();

        Update:

        «I though about sending a 'kill', but Perl doesn't seem to give me the PID.»

        Now you have one to kill.

        «The Crux of the Biscuit is the Apostrophe»

      Hello LanX,

      > (about fork) I don't wanna replicate the Perl script but spawn a PS window.

      You are already forking!

      From system

      > Does exactly the same thing as exec, except that a fork is done first and the parent process waits for the child process to exit.

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
        that's the inner implementation.°

        just show me how to do it with fork and you'll see how complicated it is.

        update

        °) and I wouldn't be too sure it's ported the same way to windows.

        IIRC is fork implemented with threads there, so there might be issues.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery