Solved

Why this will not finish?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remove Malware code from PHP file 6 74
Perl - Mawk 2 87
.properties file to call function/method 9 59
How to generate square thumbnail using perl 13 77
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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.…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

20 Experts available now in Live!

Get 1:1 Help Now