Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am running Windows XP.
Ah, that changes things considerably. You could use the standard Unix, on Windows emulated approach, such as fork. But you can use Windows specific methods, too, such as using Win32::Process. See They didn't give me a fork so I have to eat with a spawn..

As a variaton on that theme, I made a little module that, when used in a program, restarts the script with the same parameters, but without a console:

# Save as module file Win32/Detached.pm, somewhere in @INC package Win32::Detached; use strict; use Win32; use Win32::Process; use Cwd; if(@ARGV and $ARGV[0] eq '-nolaunch') { shift; } elsif(!$^C) { Win32::Process::Create( my $ProcessObj, $^X, join(" ", map { tr/ // ? qq["$_"] : $_ } $^X, $0, "-nolaunch", + @ARGV), 0, DETACHED_PROCESS, cwd, ) or die Win32::FormatMessage(Win32::GetLastError()); exit; } 1;

Simply do

use Win32::Detached;
in your main script, just making sure you don't use "-nolaunch" as a command line switch.

If that module is not handy for you — to be honest, I've rarely ever used it — you can at least borrow the parameters for the API call.

If you want to permanently run a perl script in the background, check out how to run a perl script as a service — for more detailed info, see also this online article.


In reply to Re^3: Running a process in the background by bart
in thread Running a process in the background by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-28 23:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found