cmd中颜色输出问题
这是代码:
use Cwd;
use Win32::Console::ANSI;# installed module with ppm
use Term::ANSIColor;
$parent = cwd();
@files = <*>;
print "\n";
foreach (@files)
{
$child = "$parent/$_";
if (-f $_){print "$child\n";}; #file test
if (-d $_)#directory test
{
print color("green")."$child/\n".color("reset");
my($command) = "cd $child/";#submerge one directory down ( recursive here?)
$command=~s/\//\\/g;
system( $command );
};
}
我遇到的问题是输出着色的方式。 我期望得到的是黑色背景上绿色的“某个目录”。 相反,我得到的背景颜色为绿色,文本为黑色,有时随机为白色。 我在使用 color() 的所有其他代码上都遇到这个问题。 我注意到重新启动后问题就消失了。 另外,我怀疑当我运行其他一些 Perl 代码时,问题会再次影响 DOS 及其所有窗口。基本上,一旦出错,它就会一直存在,直到每个 color() 实例重新启动为止。看起来像是一个小故障。请帮忙。
Here is the code:
use Cwd;
use Win32::Console::ANSI;# installed module with ppm
use Term::ANSIColor;
$parent = cwd();
@files = <*>;
print "\n";
foreach (@files)
{
$child = "$parent/$_";
if (-f $_){print "$child\n";}; #file test
if (-d $_)#directory test
{
print color("green")."$child/\n".color("reset");
my($command) = "cd $child/";#submerge one directory down ( recursive here?)
$command=~s/\//\\/g;
system( $command );
};
}
The problem I have is with the way output gets colored.
What I am expecting to get is "some directory" in green on black background.
Instead I get background color in green and text in black, sometimes white randomly.
I have this problem on every other code where I use color().
I noticed the problem goes away after I restart.
Also, my suspicion is that the problem returns affecting DOS and all its windows when I run some other perl code. Basically, once it goes wrong it is there until restart for every instance of color(). It looks like a glitch. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有观察到这个问题。然而,您正在使用
system
(它启动不同的 shell 来执行命令,因此实际上不会更改您的目录)这一事实可能会造成干扰。或者,如果您使用 CTRL-C 中断脚本,控制台可能会处于不确定状态。这是实现您想要的更好的方法:
I do not observe the problem. However, the fact that you are using
system
(which starts a different shell to carry out the command and therefore really does not change your directory) may be what's interfering. Alternatively, the console might be left in an indeterminate state if you are using CTRL-C to break out of the script.Here is a better way of accomplishing what you want: