1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Invoking TCC FROM Perl 5.12

Discussion in 'Support' started by David McClelland, Feb 10, 2011.

  1. David McClelland

    Joined:
    Jun 4, 2008
    Messages:
    19
    Likes Received:
    0
    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
    Bad file descriptor at C:\TestPad\debgtest.pl line 7.

    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
     
  2. ebbe

    Joined:
    Jun 2, 2008
    Messages:
    31
    Likes Received:
    0
    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
     
  3. David McClelland

    Joined:
    Jun 4, 2008
    Messages:
    19
    Likes Received:
    0
    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
     
  4. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    ---- 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
     

Share This Page