Is there a way to get a perl script to close all files handles and exit cleanly no matter what? Or to get it to spawn a process without passing any file handles or pointers to file handles to the child? So that the child process is completely free from the parent script that called it? Because exec($cmd), system(1,$cmd) Win32::Process::Create() don't work.

I am on windows server 2003. I have a bat file that is used at start up to run a java applet that sits on the machine and monitors a file for changes.

Lets say that StartJava.bat calls the command :

start /min d\java\jdk\1.4\bin\java -classpath d:\java\Thingy.jar Thingy d:\Thingything.dat

And Thingy.jar sits open in a command prompt and monitors a file.

I decided that it would be handy to have this java app started by a perl script instead of a bat file, so I could add some functionality to the startup script as well as better error handling. So now I have:

perl StartJava.pl

It works, and the app runs fine, however, when I start the java applet with perl the perl script gets locked and cannot be changed until the java applet is closed.

The thing is that when I run the bat file to start the java applet I can make changes to the bat file that started it.

This happens even if I Have StartJave.pl call the orriginal StarJava.bat which in turn calls the jar file and the StartJava.bat file closes.

Seems like perl still realizes that somewhere down the line the java app is still running. And won't let me rename or change StartJava.pl. Even though the perl process and the cmd prompt which started it have both closed.

I read some docs on perl process creation that perl passes pointers or some such to child processes back to the parents STDERR and STDOUT

I have tries several things to get perl to let go, but nothing works.

I tried using exec (StartJava.bat), I tried system(1, $cmd) I tried Win32::Process::Create()

Any ideas?


In reply to Perl file handles by CleverHanz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.