in reply to how to system call that exits

Your program does exit after qbittorrent exits. Replace your last system with exec. It will terminate your program if it succeeds, otherwise, it will return and execute your exit. In either case your program terminates.
Bill

Replies are listed 'Best First'.
Re^2: how to system call that exits
by ObiPanda (Acolyte) on Apr 27, 2024 at 19:45 UTC
    I had tried exec earlier. My obstacle was executing a windows program which has spaces in it's file path, i.e., "program files". I've tried it with double quotes, qq[], with and without the (), but it is always halting on 'C:/Program' is not recognized as an internal or external command....
    The only solution was to add the program file path to the Environmental variables PATH. I guess exec doesn't work as well as system on Windows OSs.
    exec ("qbittorrent.exe") or print STDERR "couldn't exec qbittorrent: $ +!";
      You might consider using Proc::Background, which specializes in running other processes platform-independently (with emphasis on windows), and gives you an object to monitor and kill it. Then you can also write the rest of the script to periodically check for the case of when bittorrent needs restarted, and not be blocked by waiting for system().

      You can also properly quote your filename for cmd.exe and then it will work as well:

      my $cmd = "C:\\Program Files\\qbittorrent\\qbittorrent.exe"; my @args = (...); my @cmd = (qq{"$cmd"}, @args); system @cmd == 0 or warn "Couldn't launch [@cmd]: $! / $^E";
      As Corion pointed out below, with proper quoting, both functions work the same. I find it surprising that system does work as expected without the extra quotes. I suspect that it is a difference between cmd and Windows API.
      Bill