Solved

Why this will not finish?

Posted on 2011-03-20
3
345 Views
Last Modified: 2012-05-11
I have this trivial(i thought) script run under windows with ActiveStatePerl. The problem with this script is that it will not finish.
The console is opened and never closed automatically.

#!/usr/bin/perl
#open(STDIN, "</dev/null"); # how should I do it under windows?
#open(STDOUT, ">/dev/null");
#open(STDERR, ">/dev/null");

if (0 == fork()) #child
{
      chdir('C:\Program Files\Mozilla Thunderbird');
      exec {'C:\Program Files\Mozilla Thunderbird\thunderbird.exe'} 'thunderbird' || die;
}

if (0 == fork()) #child
{
      sleep(10);
      chdir('C:\Program Files\Mozilla Firefox');
      exec {'C:\Program Files\Mozilla Firefox\firefox.exe'} 'firefox' || die;
}

exit(0);
0
Comment
Question by:ravenpl
3 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 35176814
So what is happening.

What I see is that it is making two sub-processes one opens thunderbird and the second one opens firefox.

You simply have nothing to end or destroy the objects.

What do you want to do?
0
 
LVL 43

Author Comment

by:ravenpl
ID: 35177064
> What do you want to do?
I want to spawn two subprocesses and terminate the father. However the terminal window will not shut itself. Like it ignores the exit() statement.
Additionally, if TB abd FF are already running, the perl window shuts as expected.
0
 
LVL 5

Accepted Solution

by:
group0 earned 250 total points
ID: 35185370
The last comment on the following perlmonks page has a cross-platform example of background process spawning: http://www.perlmonks.org/?node_id=663081

To make the shell run your script and exit as soon as your it is complete, you can just:

Run->cmd.exe /C script.pl
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now