Solved

Why this will not finish?

Posted on 2011-03-20
3
373 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

830 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