tcommand(cmd)

From What's New in Version 21:
You can also now call TCC via a COM interface (in TakeCmd.tlb) from scripts. The "tcommand(cmd)" function will execute any internal TCC command.

I have searched the entire help file, and this is the only reference I can find to tcommand(cmd).

It would be appreciated if someone could post working code showing how to use the tcommand(cmd), preferably using the VBScript Active Scripting Engine.

Thanks from Joe
 
May 20, 2008
11,520
102
Syracuse, NY, USA
TCC adds its COM interface to the script engine you're invoking.
Can you give a working example? This doesn't work.
Code:
v:\> type test.vbs
tcommand(dir)

v:\> script /e VBScript test.vbs

---------------------------
Script Error
---------------------------
Type mismatch: 'tcommand' - (0:0)
---------------------------
OK   
---------------------------
 
Mar 18, 2010
70
1
Does that mean it is accessible only to script engines being instantiated by TCC? (making TCC an in-process server only)

Does the TCC instance implementing the interface share the same environment and internal state as the instance which invoked a script being run by an Active Scripting engine?

It would be useful to see an example of instantiating the TCC provider of the TCC_Scripting_1 interface.

Could you say what is wrong with the following, when named silly.vbs and run via
cscript //Nologo silly.vbs
from a TCC v23 shell?
Code:
' .vbs script attempting to use TCC as a COM server
Wscript.Echo "Attempting TCC server instantiation ..."

Dim oTcc

On Error Resume Next

Set oTcc = Wscript.CreateObject("TCC_1_0.TCC_Scripting_1")
If IsObject(oTcc) Then
   Wscript.Echo "Success! Now, make the server do something."
   oTcc.tcommand("touch /c %TEMP%\tcc_automation_was_here.tmp")
   Set oTcc = Nothing
else
   Wscript.Echo "Could not instantiate TCC server."
   Wscript.Echo "Error: ", Err.Description
end if

The output is:
Code:
Attempting TCC server instantiation ...
Could not instantiate TCC server.
Error:  Could not locate automation class named "TCC_1_0.TCC_Scripting_1".
 
May 20, 2008
11,520
102
Syracuse, NY, USA
I couldn't find "TCC_1_0" in the registry.

AFAICT, no TCC-related object classes show up in OLEVIEW.EXE.

Three TypeLib's show up in OLEVIEW.EXE.
Code:
g:\tc23> regdir /d /v HKCR\TypeLib\{0474E6A3-6F13-4EE3-88F6-3E7E36367761}
HKCR\TypeLib\{0474E6A3-6F13-4EE3-88F6-3E7E36367761}
  15.0
     : REG_SZ : TCC Automation Interfaces
    0
      win32
         : REG_SZ : G:\TC21\TakeCmd.tlb
    FLAGS
       : REG_SZ : 0
    HELPDIR
       : REG_SZ : G:\TC21
  16.0
     : REG_SZ : TCC Automation Interfaces
    0
      win32
         : REG_SZ : G:\tc22\TakeCmd.tlb
    FLAGS
       : REG_SZ : 0
    HELPDIR
       : REG_SZ : G:\tc22
  17.0
     : REG_SZ : TCC Automation Interfaces
    0
      win32
         : REG_SZ : G:\tc23\TakeCmd.tlb
    FLAGS
       : REG_SZ : 0
    HELPDIR
       : REG_SZ : G:\tc23
 
Mar 18, 2010
70
1
I used Visual Studio 2017's object viewer to open TakeCmd.tlb directly.

None of the DLLs had the entry point(s) needed for regsvr32 to get them to register as an in-proc or out-of-proc server.

I have been completely unable to unearth any evidence that running scripts under TCC's script command can get an interface to TCC. (I'm not saying there is no way; just that I find no docs and my trial and error process has been all error.) However, I will give it some more trials using the CLSID's Vince found.

The tcommand method returns nothing. This makes me wonder if it is intended to be a useful feature.
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
You use it like this (using a javascript example):

testjs.js:
Code:
var d1 = "First Message";
var d2 = "echo Second Message";
var d3 = "dir /w";
TakeCommand.msgbox(d1);
TakeCommand.tcommand(d2);
TakeCommand.tcommand(d3);

Then call it thusly:

Code:
script testjs.js
 
May 20, 2008
11,520
102
Syracuse, NY, USA
Can you elaborate some?
1532803826459.png
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
OK, it works when I use the SCRIPT command. Is there anything about this in the help?

Yes, in the "what's new" section that mentions it, it is under the SCRIPT command.

I never wrote more about it for the help, because it was done for a particular commercial client and I didn't think it was particularly useful for everybody else.
 
May 20, 2008
11,520
102
Syracuse, NY, USA
What about PerlScript? Below, I see no indication at all that the script has anything past the "printf" line.

Code:
v:\> type test.pls
$a = "First Message";
$b = "echo Second Message";
$c = "dir /w";
printf("%s\n%s\n%s\n", $a, $b, $c);
TakeCommand.msgbox($a);
TakeCommand.tcommand($b);
TakeCommand.tcommand($c);
TakeCommand.garbage(trash);
garbage.trash(foo);

v:\> script test.pls
First Message
echo Second Message
dir /w

v:\>
 
Oct 9, 2015
4
0
I have had no luck using PerlScript. Croaking errors seem to be trapped and silenced.

When the following is run, $Count is 0, meaning no objects appear to be live. The GetActiveObject call does return an undef. (I'm still mystified as to whether TCC has given the scripting engine an interface to its host. It seems not.)

Code:
use Win32::OLE;
$c = "dir /w";
Win32::OLE->Initialize(Win32::OLE::COINIT_APARTMENTTHREADED);
$Count = Win32::OLE->EnumAllObjects(sub {
   my $Object = shift;
   my $Class = Win32::OLE->QueryObjectType($Object);
   printf "# Object=%s Class=%s\n", $Object, $Class;
});
print $Count, "?\n";

my $tc = Win32::OLE->GetActiveObject('TakeCommand');

if (defined($tc) && $tc != 0) { print "Hooray\n"; }
elsif (!defined($tc)) { print "Rats\n"; }
else { print "Failure trapped\n"; }

#$tc->tcommand($c);

One interesting answer to my earlier question:
This code,
Code:
var d3 = "set Poodles=Pepe,Fifi";
TakeCommand.tcommand(d3);
does appear to set an environment variable in the TCC host when the code is run as JScript using TCC's 'script' command.

It would be great if the tcommand method or an alternate for it returned error status.
 
Similar threads
Thread starter Title Forum Replies Date
L How to synthesize cmd.exe's DEL /Q Support 2
T WAD CMD incompatibility Support 14
sully9 How to? Unexpected %DATE% CMD variable format (vs DATE /T format) in CMDebug Support 1
L FTYPE in TCC, less quirky than in cmd.exe Support 3
Peter Murschall Single-line Do-CMD is a bit uncooperative. Support 6
FreezerBurnt Help making a CMD and TCC compatible batch file Support 7
T Date format date different from cmd Support 7
D Differences between TCC and CMD with COPY /b Support 4
M Oracle batch OPatch.bat.bat not working in TCC but correctly in CMD Support 5
E TCC/CMD difference Support 5
S How to? Deinstalling TC/reinstating execution of bat files by cmd in Win7 Support 31
D How to? Pass OpenHere Folder to CMD? Support 6
R Difference between TCC and CMD: variable names with hyphens Support 4
M WAD "Pictures" directory is empty in TCC but not in CMD or Explorer Support 4
rps Cmd history recall Support 4
rps Documentation TITLE cmd docs Support 0
Joe Caverly PUSHD with UNC path in CMD.EXE Support 2
W Starting program for word to pdf conversion (difference cmd and tcc) Support 13
Joe Caverly Using this CMD technique from TCC Support 17
W If command - different with CMD Support 6
I how to make TCC default/replace cmd.exe? Support 9
R FOR usage error from TCC but not from CMD Support 16
I findstr works in cmd but not in tcc Support 5
D Pasting Unicode data has different behavior on TCC and CMD Support 2
M Command line parsing differences between cmd.exe and TCC Support 6
Joe Caverly Works with CMD.EXE, no output with TCC.EXE Support 7
L WAD ECHO. expansion of non-existent env-vars differs from CMD.exe Support 6
Joe Caverly "Functions" in cmd.exe batch files Support 6
Joe Caverly Works in debugger, not from cmd line Support 1
K CMD, TCC, VisualStudio 2017, VcVars* differences Support 1
D Does TCC improve CMD's implementation of ECHO? Support 6
P Labels in batch files: TCC vs CMD.exe Support 9
Patulus Yet another thread on CMD compatibility Support 16
A Fixed (CMD compat) START /D fails to recognize the switch option. Support 3
Joe Caverly CMD.EXE and filename(1).ext Support 3
H DOS CMD Sort+Add Sequence+Remove Sequence number Support 12
T WAD Difference between TCC and CMD in handling multi-command lines Support 6
C Nested IF syntax — TCC behaving differently to CMD Support 12
T CMD incompatibility Support 14
V Network share slowness vs CMD? Support 19
P Fixed Rexx .cmd files no longer work in TCC 20 Support 3
TT's Help! Uninstalling TCC did not restore cmd.exe as Win10 default batch file processor. Support 4
R How to? Display text same as in CMD Support 14
E How to? use Executable Extensions: .bat and .cmd Support 8
D Tab completion differences with cmd.exe Support 3
deleyd Fixed Behavior different than CMD Support 1
vefatica START, CMD vs. TCC Support 0
R Difference in behavior of RMDIR vs. CMD.EXE? Support 5
jogi Problem with FOR statement in TCC but not M$ CMD Support 1
C Documentation .CMD .BAT .BTM Support 15

Similar threads