Solved

Create process, don't wait

Posted on 2000-04-08
5
802 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
ID: 2695995
Adjusted points from 200 to 300
0
 
LVL 5

Expert Comment

by:pitonyak
ID: 2696095
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
ID: 2696256
Adjusted points from 300 to 500
0
 
LVL 10

Author Comment

by:rj2
ID: 2696257
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
ID: 2696754
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

778 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