ashah21 has asked for the wisdom of the Perl Monks concerning the following question:

Scenario: I've to spawn 2 processes on windows. one is client process and second is server process. Client passes input file to server and server reads it and generate output file.

What I've done: I've used one start_comm.pl file which spawns processes using PerlACE:Process module. This module contains Process_Win32.pm which uses Win32::Process:create to spwan new process. I pass client and server parameters to start_comm.pl file which again call PerlACE module and then Win32::Process::create mathod.

Problem: Server doesn't generate any output file at desired location. Also I don't see any error while creating process or anywhere. Process just starts in new window and disappears within less than a second.

start_comm.pl
use PerlACE::Process; my $server; $server = new PerlACE::Process("$server_name", "$server_param"); $status = $server->Spawn (); $client = new PerlACE::Process("$client_name", "$client_param"); print $client->CommandLine(), "\n"; <br/> Thanks in advance. $status = $client->Spawn ();

snippet from Process_Win32.pm
Win32::Process::Create ($self->{PROCESS}, $executable, $cmdline, 0, CREATE_NEW_CONSOLE, ".");

Please let me know if I am missing something.

Replies are listed 'Best First'.
Re: Win32::Process::Create Process exits before finishing execution
by cdarke (Prior) on Jul 08, 2008 at 11:19 UTC
    Difficult to say without any errors, but a few hints for Win32::Process::Create:
    Path name must be the full, not relative, path name of the desired program. The interface does not search the normal load directories. (But see Win32::SearchPath and Win32::FetchCommand on CPAN)
    Command line should be the full command line required to run the program (mandatory).
      I have given the full path of the executable file.

      The problem I am facing is, the process is getting spawned but the main process kills it immediately rather than allowing the spawned process to terminate on its own.

      The scenario which I have is; first spawn the server process and server process will wait for the client to contact him. The server process is getting spawned and getting killed immediately. After that client process is also spawned and it is also killed immediately. I tried to print the process ids of both spawned processes and both have positive values.

      I executed the perl file independently which has the code to spawn 2 processes and it is working fine. We have a framework (with perl modules) which calls this perl file, at that time I am facing this issue.

      Is there any way to specify in the main process that do not kill the spawned processes and let them finish their job?