# Invoking TCC FROM Perl 5.12

#### David McClelland

I want to execute a "dir /bf" command from within Perl. As the "f" option is a TCC option I need to invoke TCC.EXE instead of CMD.EXE. To do this I create the environment variable:
PERL5SHELL=C:\Program Files\JPSoft\TCMD12x64\tcc.exe
and then run the program:

#!perl -w
use strict;
use 5.12.0;

say \$ENV{PERL5SHELL};
my @lns=`dir /bf `;
die \$! if (\$!);
chomp @lns;
say \$_ foreach @lns;

When I do this I get the output:

C:\Program Files\JPSoft\TCMD12x64\tcc.exe

If I do not create the PERL5SHELL then cmd.exe is invoked and the command work as expected (After I change the command to `dir /b` ).

Am I doing anything obviously wrong here or is TCC simply different from cmd.exe in a way that perl can not capture the command output stream as expected?

I am running
TCC 12.01.44 x64 Windows 7 [Version 6.1.7600]

and ActiveState Perl 5.12.2

#### ebbe

I want to execute a "dir /bf" command from within Perl. As the "f" option is a TCC option I need to invoke TCC.EXE instead of CMD.EXE. To do this I create the environment variable:
PERL5SHELL=C:\Program Files\JPSoft\TCMD12x64\tcc.exe
and then run the program:

etc. etc.
This command works in cmd.exe:

tcc.exe /c dir /bf​

Its output can be piped so I'd assume that it works with your perl program

#### David McClelland

This command works in cmd.exe:
tcc.exe /c dir /bf​
Its output can be piped so I'd assume that it works with your perl program
You are right. I can remove the PERL5LIB environment variable and then use the line:

my @lns=`tcc /c dir /bf `;

and get the expected directory listing. The down side is
1) each call results in two command shells are invoked: cmd.exe and tcc.exe.
2) The current working directory is not passed on through to tcc

It would seem that either:
1) perl is incorrectly invoking tcc or is not hooking up the output pipe correctly. Perl does hook up to cmd correctly and cmd correctly captures the output from tcc and thus passes it back to perl.
or
2) tcc is not emulating cmd.exe exactly

or I suppose, both.

In any case thanks for the solution. I hadn't thought of invoking tcc from cmd.exe

David

#### Steve Fabian

---- Original Message ----
From: David McClelland
To: ESFabian@zenge.org
Sent: Friday, 2011. February 11. 16:24
Subject: RE: [Support-t-2604] Re: Invoking TCC FROM Perl 5.12

| Quote:
| Originally Posted by ebbe
| This command works in cmd.exe:
| tcc.exe /c dir /bf
| Its output can be piped so I'd assume that it works with your perl
| program
|
| You are right. I can remove the PERL5LIB environment variable and
| then use the line:
|
| my @lns=`tcc /c dir /bf `;
|
| and get the expected directory listing. The down side is
| 1) each call results in two command shells are invoked: cmd.exe and
| tcc.exe.
| 2) The current working directory is not passed on through to tcc
|
| It would seem that either:
| 1) perl is incorrectly invoking tcc or is not hooking up the output
| pipe correctly. Perl does hook up to cmd correctly and cmd correctly
| captures the output from tcc and thus passes it back to perl.
| or
| 2) tcc is not emulating cmd.exe exactly
|
| or I suppose, both.
|
| In any case thanks for the solution. I hadn't thought of invoking tcc
| from cmd.exe

Try to insert the current directory into the command invoking TCC (without knowledge of Perl I symbolically represented it below as "cwd"):
my @lns=`tcc /c dir /bf cwd`;

As to invoking TCC without passing through CMD.EXE, try the same Perl command format that would invoke any other program (esp. text mode one, not a graphics mode one), most likely requiring the full path of TCC.EXE in the command.
--
Steve