Win32: Output to console

D

Dave...

I'm using Perl on a windows machine to automate Visual Studio .NET C++
builds each day. The command I run is the VS commandline program
devenv.exe which outputs log and error information to the console if
run directly on the commandline. For some reason I am unable to
capture or redirect this output to the console when I run the command
from Perl until the entire build is complete. Using system() I get no
ouput at all so I tried the following...

$|=1;
open(COMPILELOG, "$devenvcommand |");
while( <COMPILELOG> )
{
print;
}
close(COMPILELOG);

This does capture the output, but doesn't print it out until the
entire build is completed instead of outputing during the build. I
also tried adding 2>&1 to the command but it did not help.

Is there a way to output in real time the way it works on the
commandline or could someone explain to me why it cannot be done?

Dave...
 
J

James Willmore

On 22 Dec 2003 10:42:54 -0800
Is there a way to output in real time the way it works on the
commandline or could someone explain to me why it cannot be done?

Look over the IPC::Open2 and IPC::Open3 modules (standard with Perl).
They *may* give you what you want.

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Green light in a.m. for new projects. Red light in P.M. for
traffic tickets.
 
B

Ben Morrow

I'm using Perl on a windows machine to automate Visual Studio .NET C++
builds each day. The command I run is the VS commandline program
devenv.exe which outputs log and error information to the console if
run directly on the commandline. For some reason I am unable to
capture or redirect this output to the console when I run the command
from Perl until the entire build is complete. Using system() I get no
ouput at all

Have you closed/reopened STD{IN,OUT,ERR}? All my experience on Win32
suggests that commands run with system() from a perl process running
in a console window inherit thir STD handles from the parent, and will
output to the console if that's where they still point.

You could try system "devenv ... >CON: <CON: 2>CON:", or you could try
reopening STD{IN,OUT,ERR} to "CON:" before calling system(). You could
try uning Win32::process instead.

If you want to capture the output rather than simply have it go to the
console, I think you're out of luck. Command-line programs test
whether their input is a console; if it is, they empty their output
buffer every line, if it isn't, they buffer in huge chunks for
efficiency. Under unix you'd use a special type of file called a
'pty', which is basically a two-way pipe that pretends to be a
console. I don't think there is any equivalent on win32.

Ben
 
L

l v

Dave... said:
I'm using Perl on a windows machine to automate Visual Studio .NET C++
builds each day. The command I run is the VS commandline program
devenv.exe which outputs log and error information to the console if
run directly on the commandline. For some reason I am unable to
capture or redirect this output to the console when I run the command
from Perl until the entire build is complete. Using system() I get no
ouput at all so I tried the following...

$|=1;
open(COMPILELOG, "$devenvcommand |");
while( <COMPILELOG> )
{
print;
}
close(COMPILELOG);

This does capture the output, but doesn't print it out until the
entire build is completed instead of outputing during the build. I
also tried adding 2>&1 to the command but it did not help.

Is there a way to output in real time the way it works on the
commandline or could someone explain to me why it cannot be done?

Dave...


I do not know where you are in this post, however, here is my $.02

1. try launching a new process to exec the build command using one of
several options. Use the command 'cmd', or 'start' or use Win32::process

The following will not print until dir /s is complete
perl -e " print `dir /s`"

The following will print in real time (run cmd /? at a command prompt
for more info).
perl -e " print `cmd /c dir /s`"

start is another *cool* program provided with win 95 and above. I use
it extensively on a win 2000 server to start and capture the output of
17 separate oracle backups on 11 unix servers. (run start /? at a
command prompt for more info).
for example, your main script could run, either backtics or system(),
`start cmd /c $devenvcommand`
or keeping with my example
perl -e " `start cmd /c dir /s` "

Please note that you might want to use the /k option vs /c when using
the cmd command in order to view your build output.


2. Not sure if you need to capture the output from the build, try
redirecting the build output to a log file if one is not already
created. Then, prior to your build command, start another process to
*tail* the log file, sleep for 2 seconds before opening the log file if
needed. When the main script is done running the build command, you can
continue on and parse the build output if required; or a simple print
"\a\a"; :)

There are windows ports of the unix tail program on the net for free.
There is also a perl version of tail
http://search.cpan.org/~sdague/ppt-0.12/bin/tail
or
File::Tail
or
I seem to remember a Perl Recipe of the Day regarding a tail program (
you'll need to search for it ). It involved seek() and resetting the
EOF, sleeping, then re-reading the file.

Len
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top