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

Has anyone else had a problem with system() in the latest release of strawberry?
I need to spawn a separate process that runs independently from my main (index.pl) script so I can monitor the (child) script via pipes and have the main (index.pl) script act on the information relieved from the child process that needs to run in the background.
I have tried every conceivable format i can think of with 'system', 'exec', 'fork', 'POE::Component', 'IPC::Open3', 'IPC::Run', 'POE::Session', and 'Win32::Process', and several combinations/variations there of, but can not get a process to spawn seperate from the parent and run on. I either end up getting a "(70007)The timeout specified has expired: ap_content_length_filter: apr_bucket_read() failed" -or- "program is not recognized as an internal or external command, operable program or batch file" -or- some other similar error. Either the child process starts and hangs (waiting for the child to finish I assume, which it won't) or not launch the child at all.
The child is a node.js script that runs fine if I type the command from the windows command prompt.
I just recently switched from activestates perl to strawberry (v5.20.1) for MSWin32-x86-multi-thread-64int because activestate kept insisting I had to upgrade to business ($$$$) to install some of the key modules I need.
The OS is windows XP/sp3 and my project has come to a halt until I can get this 'child' script to startup, I don't want to have to start the child, everytime I startup the webserver, I just want my index.pl to spawn it out when it starts up.
You guys have been very helpful to me over the years and pretty much got me straightened out in my adventures... And I appreciate any insight as to what I'm doing wrong here. Thanx for listening to my sob story, and thanx a gig...
-Gary


I tried re-inventing the wheel again, but everytime I push it, it still falls flat on it's side...

Replies are listed 'Best First'.
Re: system() function
by Anonymous Monk on Feb 08, 2015 at 23:44 UTC

      Thanx Anonymous Monk, I studied what you proposed and came up with this:

      use Win32::ShellQuote(); use Win32::Process(); my(@Node_Exe_Location) = ['C:\Program Files\nodejs\node.exe']; my(@Child_Script_To_Run) = [ 'node', 'I:\HTTPS\prinet.org\site\assets\javascript\child-module.js' ]; Win32::Process::Create( $Child_Module, Win32::ShellQuote::quote_system_string(@Node_Exe_Location), Win32::ShellQuote::quote_system_string(@Child_Script_To_Run), 0, Win32::Process::DETACHED_PROCESS(), ".", ) or do { my($err) = int($!).' '.$!." #### ".int($^E)." $^E "; warn "??? - CreateProcess failed $err "; };


      I have tried several variations of single quote, double quote, escaped and non-escaped slashes/back slashes to no avail. The closest I have got is the above code, but I'm getting "??? - CreateProcess failed 0 #### 123 The filename, directory name, or volume label syntax is incorrect" in the error log. I seriously appreciate your direction, but I'm having trouble understanding the syntax somehow. I'm assuming that "Win32::Process::DETACHED_PROCESS()" is something I wasn't aware of and that is one of the keys to what I'm attempting, but the "Win32::ShellQuote()" is what I'm misunderstanding somehow. Could you enlighten me a wee bit more? Oh, yea, thank you for what you provided, I'm going to keep experimenting here...
      -Gary


      I tried re-inventing the wheel again, but everytime I push it, it still falls flat on it's side...
        You use quote_system_string, but you don't use system. quote_native sounds more appropriate.