I tried to forward input, output and error of a command to files using
open3 on windows.
I used the following code:
open(F_IN, "<$f_in");
open(F_OUT, ">$f_out");
open(F_ERR, ">$f_err");
my $pid = open3(\*F_IN, \*F_OUT, \*F_ERR, "$command");
waitpid($pid, 0);
Anything, this code does, is hanging on waitpid.
Does open3 work on windows? If yes: How can I use it to forward all
input/output channels to files?
Thanks in advance
CU
Manuel
open3 doesn't work like this: it opens the handles for you.
Under sane versions of windows (Win2k and later) you can use
system "$command <$f_in >$f_out 2>$f_err";
just as under Unix. Alternatively, you can use IPC::Run, which I would
recommend.
Ben
--
Many users now operate their own computers day in and day out on various
applications without ever writing a program. Indeed, many of these users
cannot write new programs for their machines...
-- F.P. Brooks, 'No Silver Bullet', 1987 [b...@morrow.me.uk]
open3 uses pipes to open the filehandles, but Win32 dosn't
handle pipes well,
Use IPC::Run or IPC::Cmd on Win32, it uses sockets instead of pipes,
and win32 can handle it.
See
http://perlmonks.org?node_id=593769
for other ideas.
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Could you please elaborate on what you mean by, "doesn't[sic] handle
pipes well" ?
I find under 2000 and XP I can use pipes just as I can in a Linux/UNIX
environment.
E.G. :
ls -l | egrep "^d" | sort
some_program_with_lots_of_output | more
grep "1.2.3.4" access_log | tail -n 25
ls -l long_dir | less
(Note that some of these examples use Win32 ports of Linux uilities like
grep, sort, ls, tail, less... etc, which I use on all my Windows systems
so I can things in a similar manner on either win or nix :-) )
--
szr
>zentara wrote:
>>>
>>> Does open3 work on windows? If yes: How can I use it to forward all
>>> input/output channels to files?
>>>
>>> Thanks in advance
>>
>> open3 uses pipes to open the filehandles, but Win32 dosn't
>> handle pipes well,
>
>Could you please elaborate on what you mean by, "doesn't[sic] handle
>pipes well" ?
In win32, select won't work reliably on pipes, and you need select's
can_read method to know when there is output available in the pipe.
>
>I find under 2000 and XP I can use pipes just as I can in a Linux/UNIX
>environment.
>
>E.G. :
>
> ls -l | egrep "^d" | sort
> some_program_with_lots_of_output | more
> grep "1.2.3.4" access_log | tail -n 25
> ls -l long_dir | less
>
>(Note that some of these examples use Win32 ports of Linux uilities like
>grep, sort, ls, tail, less... etc, which I use on all my Windows systems
>so I can things in a similar manner on either win or nix :-) )
Those are pipes used in a different context, since the commands close,
and thus flush the pipe.
You can use pipes, but IPC::Open3 needs select to know when the
pipes have readable data.
If you watch carefully, you may see IPC::Open3's output when you close
the program or filehandle, which will cause it to flush.
See
http://perlmonks.org?node_id=621058
for an explanation.
The is the Win32::Pipe and Win32::IPC modules which help.