Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem calling dos color command from tcl

Status
Not open for further replies.

mjcorri

Programmer
Jun 23, 2009
3
US
I'm trying to change the font color of the command prompt by executing "color 09" from a tcl script. I got an error so I tried executing the command in a bat file. I make the call:

catch [ exec ChangeColor.bat "0A" ]

ChangeColor.bat is just:
color %1

This doesn't work though.

 
This works
sys.tcl
Code:
set cmd "|mycmd.bat"
set f [open $cmd "r"]
close $f
where
mycmd.bat is:
Code:
start color 0A
But it doesn't change the font color in the recent command window, insted it opens new command window (with green on black).


 
I'm trying to change the color of the recent window. I tried using your solution and taking out the start from the bat file, but that wont work. Do you know why?
 
I'm on windows Vista and that works.
Have you exactly copied the code I posted above? For example if you forget the pipe character "|" in
Code:
set cmd "[COLOR=red]|[/color]mycmd.bat"
then it will not work.
 
This works too
Code:
set cmd "mycmd.bat"
exec $cmd
or this
Code:
exec cmd /c start color 0A
But both of the above scripts opens new colored window, because they used the START command. Without START command it doesn't work.

I tried to execute this command in another languages too:
Perl
Code:
use strict;
use warnings;

my $rc=system("color 0A");
print "\$rc = $rc\n"

Python
Code:
import os

rc=os.system("color 0A")
print "rc = %d" % rc

REXX
Code:
md = "color 0A"
cmd
say "rc = " || rc

All the above code examples in Perl, Python, REXX (ooRexx and Regina) work in windows without problems and (in difference to Tcl) they colors font in the current window.

It seems to be somethng wrong with Tcl on windows (I'm using ActiveTcl) - I don' know what's wrong, but if I would you I would rather use other language for the given purpose on windows.
 
Thanks for the help. I'd switch but I'm already to invested in the tcl script I have now. Thanks again though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top