#!/usr/bin/perl
use strict;
use warnings;
use POSIX ":sys_wait_h";
# make STDOUT flush immediately
$| = 1;

my $cmd;
$cmd = "/cygdrive/c/WINDOWS/Microsoft.NET/Framework/v3.5/MSBuild.exe -version";
run_cmd($cmd);
$cmd = "/cygdrive/c/WINDOWS/SYSTEM32/cmd.exe /c ver";
run_cmd($cmd);

sub run_cmd {
    my ($program) = @_;
	print "\nRunning command: $program\n";
	my $pid = open(KID_TO_READ, "-|");
	defined($pid) || die "can't fork: $!";
	if ($pid) { # parent
		while (<KID_TO_READ>) {
			print $_;
		}
		close(KID_TO_READ) || warn "kid exited $?";
	} else { # child
		#($EUID, $EGID) = ($UID, $GID); # suid only
		exec($program,)
		|| die "can't exec program: $!";
		# NOTREACHED
	}
}