doskey execute command

  • Thread starter Thread starter Gnooby
  • Start date Start date
G

Gnooby

Hi,

I'm trying to make the cmd.exe window display the current working
directory in the title. I managed to do do this somehow, but I'm not
totally satified with the solution. Please take a look:

I created a file named startup.bat. It contains the following:

doskey /macrofile=c:\macrofile.mac

The macrofile.mac contains

cd=(CD $* && c:\set_title.bat)

set_title.bat contains:

@echo off
title %CD%

Then I made the cmd.exe link execute the startup.bat file:
%SystemRoot%\system32\cmd.exe /k c:\startup.bat

This works just fine, but I'm curious how I could do this with just one
file/command. I'm quite a newbie to shell scripting, and I'm simply
missing some syntactic details. So, how would you do this with just
one entry in startup.bat? Obviously none of the following works:

doskey cd=(CD $* && title %CD%)
doskey cd=CD $* $t title %CD%

Of course, this must fail because %CD% is expanded when the 'doskey'
command is executed and not when the 'cd' command is executed.

I don't get the syntax either:
- What about the parenthesis? Do I need them?
- What is the right way to concatenate the commands? '&&' or '$t' ?

I tried to find a decent tutorial/howto, but the Web is flooded with
the spare command reference :-)

Have a nice day.
 
This seems to work.

doskey cd=cd $* ^& call title ^^%cd^^%
I'm trying to make the cmd.exe window display the current working
directory in the title. I managed to do do this somehow, but I'm not
totally satified with the solution. Please take a look:

I created a file named startup.bat. It contains the following:

doskey /macrofile=c:\macrofile.mac

The macrofile.mac contains

cd=(CD $* && c:\set_title.bat)

set_title.bat contains:

@echo off
title %CD%

Then I made the cmd.exe link execute the startup.bat file:
%SystemRoot%\system32\cmd.exe /k c:\startup.bat

This works just fine, but I'm curious how I could do this with just one
file/command. I'm quite a newbie to shell scripting, and I'm simply
missing some syntactic details. So, how would you do this with just
one entry in startup.bat? Obviously none of the following works:

doskey cd=(CD $* && title %CD%)
doskey cd=CD $* $t title %CD%

Of course, this must fail because %CD% is expanded when the 'doskey'
command is executed and not when the 'cd' command is executed.

I don't get the syntax either:
- What about the parenthesis? Do I need them?
- What is the right way to concatenate the commands? '&&' or '$t' ?

I tried to find a decent tutorial/howto, but the Web is flooded with
the spare command reference :-)

Have a nice day.

Clay Calvert
(e-mail address removed)
Replace "W" with "L"
 
* Clay Calvert said:
This seems to work.

doskey cd=cd $* ^& call title ^^%cd^^%

Awesome!
Just a minor detail: How would I put this into the appropriate file?
The command works just fine when executing it directly at the
cmd-prompt. I tried to put it as-is into c:\startup.bat, in order to
be able to execute it via the cmd-link
%SystemRoot%\system32\cmd.exe /k c:\startup.bat

When doing so (i.e.: when putting it into c:\startup.bat, instead of
executing it manually at the cmd-prompt), after executing a command like
cd c:\drivers
cmd gives me a prompt, asking "More?" (I assume that's the proper
translation, as I'm working on a german system, where it actually
promts "Mehr?")

Thanks!
 
Awesome!
Just a minor detail: How would I put this into the appropriate file?
The command works just fine when executing it directly at the
cmd-prompt. I tried to put it as-is into c:\startup.bat, in order to
be able to execute it via the cmd-link
%SystemRoot%\system32\cmd.exe /k c:\startup.bat

When doing so (i.e.: when putting it into c:\startup.bat, instead of
executing it manually at the cmd-prompt), after executing a command like
cd c:\drivers
cmd gives me a prompt, asking "More?" (I assume that's the proper
translation, as I'm working on a german system, where it actually
promts "Mehr?")

"More" is correct.

Double the percent signs.

doskey cd=cd $* $T call title ^^%%cd^^%%

$T is probably more robust.

Clay Calvert
(e-mail address removed)
Replace "W" with "L"
 
* Clay Calvert said:
doskey cd=cd $* $T call title ^^%%cd^^%%

U da man, Clay. U da man.

Thanks a million!

BTW: can you recommend an online tutorial/howto for these kind of
things?

Thanks again! Have a nice day.
 
U da man, Clay. U da man.

Thanks a million!

BTW: can you recommend an online tutorial/howto for these kind of
things?

Learning by example:

http://www.commandline.co.uk

http://www.fpschultze.de/bsh.htm

http://www.robvanderwoude.com

Also, read the outputs of:

for /?
set /?
cmd /?
find /?
findstry /?
and if /?

Here is a crib sheet I put together to (try to) keep variable
expansion straight.

----- Parsing.txt --------

The following are examples of variable substitution and parsing in
Windows NT, 2000 and XP.
A "#" character will indicate functionality only available in Windows
2000, and XP.

More information can be found from running "Set /?" and "For /?".

A "one-sided" variable is a single character variable that has a
single percent sign preceding the character. Examples: %1 and %a


"Two-sided" variables can have more than one character and have a
percentage sign on both sides.
Examples: %temp% and %path%

The following string will be used for these examples:

set test=123456789abcdef0

Substitution [: and =] Two sided only

%PATH:str1=str2%
%PATH:str1=%
%PATH:*str1=str2%

%Test:ab=xy% 123456789xycdef0
%Test:ab=% 123456789cdef0
%Test:*ab=% cdef0
%Test:*ab=XY% XYcdef0


Parsing [%:~X% and %:~X,Y%] Two sided variables only

Extract only the first 5 characters
%test:~0,5%
12345

Skip 7 characters and then extract the next 5
%test:~7,5%
89abc

Skip 7 characters and then extract everything else
%test:~7%
89abcdef0

Extract only the last 7 characters #
%test:~-7%
abcdef0

Extract everything BUT the last 7 characters #
%test:~0,-7%
123456789

Extract between 7 from the front and 5 from the back #
%test:~7,-5%
89ab

Go back 7 from the end then extract 5 towards the end #
%test:~-7,5%
abcde

Extract between 7 from the end and 5 from the end #
%test:~-7,-5%
ab


[%~letter] One sided variables only

%~I removes any surrounding quotes (") #
%~fI Fully qualified path name
%~dI Drive letter only
%~pI Path only
%~nI file Name only
%~xI eXtension only
%~sI Short names only
%~aI Attributes #
%~tI Time and date of file #
%~zI siZe of file #

[%~$string]
%~$PATH:I searches the PATH and expands to the full name of the
first found

The modifiers can be combined to get compound results:

%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:i - searches the PATH and expands to the drive letter and
path of the first found
%~ftzaI - expands %I to a DIR like output line #

In the above examples %I and PATH can be replaced by other valid
values. The %~ syntax is terminated by a valid FOR variable name.
Picking upper case variable names like %I makes it more readable and
avoids confusion with the modifiers, which are not case sensitive.


Clay Calvert
(e-mail address removed)
Replace "W" with "L"
 
This is how I did it with a shorctcut to cmd
%SystemRoot%\system32\cmd.exe /k doskey /macrofile=F:\jpd\macros.ini


Gnooby said:
* Clay Calvert said:

Bookmarked. Thanks.
Also, read the outputs of:

for /?
set /?
cmd /?
find /?
findstry /?
and if /?

Wha?!? All of them? Even the 'cmd' thingie? ;-)
Here is a crib sheet I put together to (try to) keep variable
expansion straight.
[ --- snip --- ]

Looks great. Lots to learn. Thanks a lot!
 
Back
Top