why does my cmd.exe process doesn't have the “title” property set when launched as a service through perl?

StackOverflow https://stackoverflow.com/questions/10229725

Question

I'm making my Perl soft runing as a service on windows.

For this purpose I'm using the Win32::Daemon module to manipulate SCM (service configuration manager) and start/stop my service.

To launch my service, I use the system() perl command.

The command looks like:

START \"title\" /Dc:\\path\\to\\bat\\script\\dir\\ \"script.bat\"

When I launch this command directly from cmd.exe, the title of the process is well set.

When the command is launched through the service I start, the process has an empty title. Task manager says that the launched command is:

cmd /c ""C:\path\to\script.bat" "

Am I missing something?

note: I'm definitly trying to set a title to my service, because I didn't find a cleaner way to stop it than launching a "taskkill" command in the stop hook of the service, with the title name as a parameter (don't know how to catch the PID of the generated process)

Thanks.

Was it helpful?

Solution

I'm not 100% sure what your issue is, but the title command may help.

When a cmd process starts in Windows, it gets a default widow title. The DOS "title" command can set the window title to whatever you like.

The DOS "start" command is used to split (fork?) the command to a new window, which separates it from the calling DOS/cmd window (unless you use the correct start parameters to keep it in the same window). Part of the start command is the optional "title" parameter which sets the window title for you.

But you mentioned running as a service... services don't generally have windows or GUIs, so I'm not sure why you're so interested in the window title.

In the end, you can put

title "The title of the window"

in your batch script... or if you're in a Perl program, doing

system "title \"Window title\"";

will also work.

OTHER TIPS

Try to execute your commadn like. The windows has two commandshell if I remember correctly, if you use cmd.exe you always use the new one.

http://ss64.com/nt/cmd.html

cmd.exe /C START \"title\" /Dc:\\path\\to\\bat\\script\\dir\\ \"script.bat\"

You can also use the perl module Term::Title to set the title on the console, and it's cross platform too:

use Term::Title 'set_titlebar', 'set_tab_title';

set_titlebar("This goes into the title");

set_titlebar("Title", "And also print this to the terminal");

set_tab_title("This goes into the tab title");

set_tab_title("Tab Title", "And also print this to the terminal");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top