Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Perl Pipeline exception handling

by BrowserUk (Patriarch)
on Jul 19, 2016 at 21:29 UTC ( [id://1168075]=note: print w/replies, xml ) Need Help??


in reply to Perl Pipeline exception handling

It is very unusual to call a .pm file as a command?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Perl Pipeline exception handling
by perl_diver (Initiate) on Jul 25, 2016 at 16:18 UTC

    Sorry typed it wrong. Actually I'm calling the perl interpretor:

    system "perl PipeLine.pm $f my.Config.ini";

      I've a slightly different question but relevant in this context I guess:

      If I want to open an errorlog file in the main calling program , how can I pass the filehandle as argument to each subsequent script call ?

      Thanks

        Inheritance of file handles in child processes is very similar between Unix and Windows. All of the same concepts are there in both places, but they have different names and are manipulated using different functions. Perl layers the Unix-style concepts over the top of the Windows equivalents. If you want to have a Perl child process on Windows inherit a file handle, it requires you to use the Windows concepts and then rewrap them in the Unix equivalents so Perl can use them (because Perl only does that for you automatically for STDIN, STDOUT, and STDERR). Win32API::File (bundled with Perl) provides all of the tools you need to do this.

        In Unix, to share a file handle with a child process that is not running the same script, that is, when you did fork(2) followed by exec (perhaps indirectly, such as via system), you have to:

        1. mark the file descriptor as "do not close on exec" (there are 2 ways to do that)
        2. fork the child and exec the new program in the child
        3. inform the child of the file descriptor (a small integer)
        4. have the child re-open the file descriptor (by passing something like "<&=$fd" to open)

        In Windows, the steps are almost the same. Instead of a file descriptor, you deal with a native Windows "file handle" (a pointer, which is just a large integer), which you must not confuse with a Perl "file handle". The Windows steps are:

        1. mark the native handle so it will be inherited [using HANDLE_FLAG_INHERIT]
        2. spawn the child (don't use Perl's fork as that doesn't spawn a child, it creates a thread and a new interpreter instance)
        3. inform the child of the native handle, a large integer [requires GetOsFHandle()]
        4. have the child re-open a Perl file handle that just wraps the given native handle [using OsFHandleOpen()]

        I've done this successfully without much trouble before. I thought I'd posted code for such here but my search did not turn such up. I might rewrite that later and post it.

        See also: Re^2: Passing a File Descriptor to a New Process on Windows (Win32API::File)

        - tye        

        I haven't tested this, but I believe that if you (re)open stderr to point to your logfile, and each of your subscripts simply write to stderr, then all the output will end up in the log file.

        You could also pass the name of the file as an argument to each of the subscripts and have each of them open it individually; though -- on windows at least -- you would have to close it in your main script before calling the subscripts.

        Actually passing file handles between separate processes doesn't work.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1168075]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found