Solved

Create process, don't wait

Posted on 2000-04-08
5
798 Views
Last Modified: 2012-05-04
Does Perl have a way to create another process that works on both Win32 and Unix? I dont want to wait on the newly created process.
0
Comment
Question by:rj2
  • 3
5 Comments
 
LVL 10

Author Comment

by:rj2
Comment Utility
Adjusted points from 200 to 300
0
 
LVL 5

Expert Comment

by:pitonyak
Comment Utility
I had an application where I wanted to kick off a process to run in the background on Perl and I also wanted to grab the output.  To do this, I wrote a batch file that ran under windows and used the start command to kick off a process in the background and I wrote a ksh script that ran under unix which simply ran the program in the background.

In my perl code I then checked to see if my OS was MSWIN32 (I think this is what it is called)

if ($^O eq "MSWIN32") {
  system('mybatch.bat');
} else {
  system('myshell.ksh');
}

Or something like that. If you have the latest PERL for windows it may support the fork() function which is really what you want but it is newly supported on windows.

I can probably provide a better code example if it is really required but I have to go looking for it..

Andy
0
 
LVL 10

Author Comment

by:rj2
Comment Utility
Adjusted points from 300 to 500
0
 
LVL 10

Author Comment

by:rj2
Comment Utility
One important addition:
It'a a CGI script.
I sometimes regenerate some files. This take some time. I want to return results based on the existing files and
start another independent process that does the regeneration, so the user don't have to wait.

I tried using fork, but when I ran it in the browser, it still waited until the other process had finished, also if the child called POSIX::setsid.

Is there a way around this?
It's enough that it works on Unix.
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
Comment Utility
Close STDOUT (that should effectively end the CGI scripts communication with the client) and then start the regeneration.

e.g.,

# Display your page based on current files
print "Content-type: text/html\n\n";
print "<HTML><BODY>Page Content</BODY></HTML>";

# flush and close STDOUT, ending communication
close STDOUT;

# Do regeneration tasks...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

771 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

10 Experts available now in Live!

Get 1:1 Help Now