Great monks of Perl,

I have to port to Windows, and in Perl, a set of ksh scripts. These scripts use redirections to one unique error file for different commands. That is they do things like :

cmd_uno >> cmd_uno_out 2>> general_err & cmd_dos >> cmd_dos_out 2>> general_err &
Every command launched is a different script or binary. They can be system commands or written by others persons, some may run in the background for a long time. The number and nature of these command is not controlled by me and will vary. They should run at the same time.

Is this single file redirection not at all possible with windows ? I tried several approaches :
- redirection through a cmd shell
- passing the filename as a parameter before spawning - passing already opened IO::File filehandles

Everytime I get a "File already used by another process" error. It seems strange that something so easy with Unix is impossible with windows, so maybe i'm missing something ? Is this a well known problem ? What are the workarounds ? Is it done with other languages ?

Another problem is that i work with Perl 5.6 and so i do not have Win32::Job. This module allows to redirect STDERR and STDOUT of the spawned process to files specified at launch time. Since i cannot do this I have to impose that the commands are either doing the redirections themselves or launched through a cmd shell that does the redirections for them.

Add these two problems and you see that i have to :

I must add that i cannot use other modules than pure perl ones or the ones that are in the standard 5.6 distribution

I already have some code running, but maybe someone here can give me ideas on trying to make this as clean as possible. What do you think ?


In reply to Win32 multiple process and single file redirection by ZlR

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.