Solved

Create process, don't wait

Posted on 2000-04-08
5
808 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
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…
Six Sigma Control Plans

636 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