By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,236 Members | 1,809 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,236 IT Pros & Developers. It's quick & easy.

Setting console title doesn't work

P: n/a
Hello,

I wrote a trivial program to set the console title in a console
application. Here is the code:-

namespace myns
{
class SetTitle
{
static void Main ( string [] args )
{
if ( 0 >= args.Length || 0 >= args [ 0 ].Length )
System.Console.WriteLine ( System.Console.Title );
string title = args [ 0 ];
if ( title.StartsWith ( @""" ) )
title = title.Substring ( 1 );
if ( title.EndsWith ( @""" ) )
title = title.Substring ( 0, title.Length - 1 );
System.Console.Title = title;
}
}
}

However, when executing from the command line (ran cmd.exe and switched
to output dir), the shell title does not change.

On the other hand, if I step through the program in Visual Studio, the
console popped up by Visual Studio does have its title changed.

Any ideas on this?

thanks,

-vijai.

Sep 20 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
I tried simplifying the program as follows, but that didn't work
either.
namespace myns
{
class SetTitle
{
static void Main ( string [] args )
{
if ( 0 >= args.Length || 0 >= args [ 0 ].Length )
System.Console.WriteLine ( System.Console.Title );
System.Console.Title = title;
}
}
}
thanks,

-vijai.

Sep 20 '06 #2

P: n/a
vi**********@gmail.com wrote:
I wrote a trivial program to set the console title in a console
application. Here is the code:-

namespace myns
{
class SetTitle
{
static void Main ( string [] args )
{
if ( 0 >= args.Length || 0 >= args [ 0 ].Length )
System.Console.WriteLine ( System.Console.Title );
string title = args [ 0 ];
if ( title.StartsWith ( @""" ) )
title = title.Substring ( 1 );
if ( title.EndsWith ( @""" ) )
title = title.Substring ( 0, title.Length - 1 );
System.Console.Title = title;
}
}
}

However, when executing from the command line (ran cmd.exe and switched
to output dir), the shell title does not change.
Are you aware that the title is restored when the program
exits ?

And when run in non debug the time between setting the title
and exiting is very short.

Arne
Sep 20 '06 #3

P: n/a
But, I find that very weird. Setting the console background or
foreground colors persists even after the application that set them
exits. Then why not the title?

-vijai.

Arne Vajhøj wrote:
vi**********@gmail.com wrote:
I wrote a trivial program to set the console title in a console
application. Here is the code:-

namespace myns
{
class SetTitle
{
static void Main ( string [] args )
{
if ( 0 >= args.Length || 0 >= args [ 0 ].Length )
System.Console.WriteLine ( System.Console.Title );
string title = args [ 0 ];
if ( title.StartsWith ( @""" ) )
title = title.Substring ( 1 );
if ( title.EndsWith ( @""" ) )
title = title.Substring ( 0, title.Length - 1 );
System.Console.Title = title;
}
}
}

However, when executing from the command line (ran cmd.exe and switched
to output dir), the shell title does not change.

Are you aware that the title is restored when the program
exits ?

And when run in non debug the time between setting the title
and exiting is very short.

Arne
Sep 21 '06 #4

P: n/a
vi**********@gmail.com wrote:
But, I find that very weird. Setting the console background or
foreground colors persists even after the application that set them
exits. Then why not the title?
Good question.

I do not have the answer.

Arne
Sep 21 '06 #5

P: n/a
That's normal, the console colors are persisted (in the registry), the title
is volatile , it remains for the cmd session and is initially set by
cmd.exe.
Note that changing the console colors in an application without restoring
the original colors back is a bad coding practice, an application running in
the command interpreter (cmd) is not owning the console window, it's the
cmd.exe who owns the console, so you need to restore all it's properties
when done with your application.

Willy.

<vi**********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
But, I find that very weird. Setting the console background or
foreground colors persists even after the application that set them
exits. Then why not the title?

-vijai.

Arne Vajhøj wrote:
vi**********@gmail.com wrote:
I wrote a trivial program to set the console title in a console
application. Here is the code:-

namespace myns
{
class SetTitle
{
static void Main ( string [] args )
{
if ( 0 >= args.Length || 0 >= args [ 0 ].Length )
System.Console.WriteLine ( System.Console.Title );
string title = args [ 0 ];
if ( title.StartsWith ( @""" ) )
title = title.Substring ( 1 );
if ( title.EndsWith ( @""" ) )
title = title.Substring ( 0, title.Length - 1 );
System.Console.Title = title;
}
}
}

However, when executing from the command line (ran cmd.exe and switched
to output dir), the shell title does not change.

Are you aware that the title is restored when the program
exits ?

And when run in non debug the time between setting the title
and exiting is very short.

Arne

Sep 21 '06 #6

P: n/a
Ah. True. But, I am trying to write a set of utilities to customize the
command window. I use 4NT at work and would like to be able to
customize the command shell like 4NT allows. Just an interesting though
possibly useless project :)

Willy Denoyette [MVP] wrote:
That's normal, the console colors are persisted (in the registry), the title
is volatile , it remains for the cmd session and is initially set by
cmd.exe.
Note that changing the console colors in an application without restoring
the original colors back is a bad coding practice, an application runningin
the command interpreter (cmd) is not owning the console window, it's the
cmd.exe who owns the console, so you need to restore all it's properties
when done with your application.

Willy.

<vi**********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
But, I find that very weird. Setting the console background or
foreground colors persists even after the application that set them
exits. Then why not the title?

-vijai.

Arne Vajhøj wrote:
vi**********@gmail.com wrote:
I wrote a trivial program to set the console title in a console
application. Here is the code:-
>
namespace myns
{
class SetTitle
{
static void Main ( string [] args )
{
if ( 0 >= args.Length || 0 >= args [ 0 ].Length )
System.Console.WriteLine ( System.Console.Title );
string title = args [ 0 ];
if ( title.StartsWith ( @""" ) )
title = title.Substring ( 1 );
if ( title.EndsWith ( @""" ) )
title = title.Substring ( 0, title.Length - 1 );
System.Console.Title = title;
}
}
}
>
However, when executing from the command line (ran cmd.exe and switched
to output dir), the shell title does not change.
Are you aware that the title is restored when the program
exits ?

And when run in non debug the time between setting the title
and exiting is very short.

Arne
Sep 21 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.