Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: how to system call that exits

by BillKSmith (Monsignor)
on Apr 27, 2024 at 19:01 UTC ( [id://11159115]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11159115]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2026-04-12 00:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.