473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Setting console title doesn't work

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
6 4856
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Peter | last post by:
L.S. I am developing a PHP-login script (on Lycos Tripod) that uses Session to pass on variables. Below is the entire (stripped) structure that I use. It opens a page where you can Set and Read...
6
by: Reid Goldsborough | last post by:
Hi. I'm a JavaScript neophyte. I'm trying to create a JPEG animation, with one coin (tet) morphing into another. The code doesn't work. Anybody feel like taking a shot at correcting me? It's short....
3
by: Sonya | last post by:
Dear list; I am a css newbie, and hope you can help. I am trying to make my page print out horizontal when user hits a print button in my page. the print button invokes javascript print.window()...
3
by: niconedz | last post by:
Hi The following code works fine in IE but not Firefox. It's a little script that zooms an image and resizes the window to fit. Can anybody tell me what's wrong? Thanks Nico == btw.....
6
by: crcucb | last post by:
Can anyone tell me why this page: <head> <Title>testpage</title> </head><body> <span title="test">Test</span> </body> </HTML> Doesn't work in IE 6 but works in FF?
0
by: Wayne Erfling | last post by:
I put in the code below to disable self links in a menu control in a "master" page. It works properly if the top-level menu item has no children, but both ..Selected = false and .NavigateUrl =...
5
by: celestialgal86 | last post by:
Hi everyone... I'm a starter at .Net programming, and I need some help. I was asked to develop a console app that will auto-hide the console window and show a system tray icon. And by...
3
by: MM | last post by:
Hi everybody, what do you think about this problem? I want to create a HTML header file with 2 variables, as below: ----------------------------- $title = "Title of document"; $style =...
2
by: namratha247 | last post by:
Hi, Can anybody please help me with this problem. In my application, I'm using Menus. and the CSS for the menu is as given below ccMenu.css /* Root = Horizontal, Secondary = Vertical */...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.