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

hi at all,
how can i wright a log file from each consolen output?
exampel witch is not working :-(
use strict; use Win32::Process; use Win32; open (STDOUT, "| tee >t2.txt"); my $ProcessObj = ""; Win32::Process::Create($ProcessObj, "D:\\WIN32APP\\JRE_142_03\\bin\\java.exe", "java.exe -version" >>*STDOUT, 1, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport(); $ProcessObj->Suspend(); $ProcessObj->Resume(); $ProcessObj->Wait(INFINITE); } close(STDOUT);
thanks in advanced
wrbrgds
rambo

Replies are listed 'Best First'.
Re: logging of win32::process
by wazoox (Prior) on May 04, 2005 at 13:50 UTC
    You're trying to pipe the output to the "tee" command, which is an Unix command and probably isn't available on windows unless you installed Cygwin or a similar utility package.
    Of course you could install Cygwin, but.... ;) This node 453546 relates closely to your problem and may provide some answers, like the module IO::Tee.
      hi, thanks for response! to using tee it's just a test for me but does't work,
      my problem is how can i implement the logging on win32::process?
      something like this
      start logging
      start process
      end process
      stop logging
      and everything needs to be on console and file.
        I understand your problem. Please check the links I provided; IO::Tee is a perl package that provides the "tee" command functionality to your scripts, so it should fit your need, and there may be some other suggestions in the node I mentioned.
Re: logging of win32::process
by starbolin (Hermit) on May 04, 2005 at 17:13 UTC

    Hi Rambo Welcome to Perlmonks;

    To have the output of your process available inside your perl script you would need to open a pipe then read from that pipe. Like this:

    use warnings; use strict; my $file= "capture.txt"; my $command= "ls"; open ( FILE, ">$file") or die "Can't open $file, stopped"; open ( PIPE, "$command |") or die "Can't open pipe, stopped"; while (<PIPE>) { print ; print FILE; }
    Of course, this just opens $command as a child of your script. Giving you access to the output only. If you need to start a fully interactive process this is much harder. You might read perlipc.

    ammended

    See 'tee' with pipes for a command-line filter using this technique.


    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}