Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Restarting a Perl script on Windows 10

by petro4213 (Acolyte)
on May 07, 2020 at 08:31 UTC ( [id://11116532]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Restarting a Perl script on Windows 10
in thread Restarting a Perl script on Windows 10

The solution

exec(qw/wmic process call create/ => "CommandLine='wperl $pathToMyself'");

works fine, as long as the script to call (pointed to by $pathToMyself) doesn't require additional command line parameters.

I know, that this is not a Perl issue, but would you have a solution on how to add command line parameters to this call? I must admit that I don't understand the wmic docs...

Replies are listed 'Best First'.
Re^4: Restarting a Perl script on Windows 10
by jcb (Parson) on May 07, 2020 at 23:33 UTC

    WinDOS uses the DOS model and does not pass arguments to invoked processes, only a "command tail" string that all Windows C runtime libraries parse into argc and argv using some rules or other.

    Using wperl as in your example means that $pathToMyself is already being passed as the "command tail" to wperl. Try:

    my $argtail = join ' ', @args; exec(qw/wmic process call create/ => "CommandLine='wperl $pathToMyself + $argtail'");

    If you are wondering, yes, this does mean that arguments containing whitespace are a problem. Quoting is handled by C runtime library startup code and that can vary from program to program because there is no standard system C runtime library on Windows.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found