Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to send a path as an argument to an executable.
what I want to do something like this:

pushd some\folder
set x=cd
MyExe.exe %x%

the problem is that the x variable is now equal to the string "cd" but what I want is to get the output of cd into x.
How do I do that?

share|improve this question
I wasn't quite understanding what you wanted - why can't you just use the %1%, %2% etc variables if you are passing parameters into the script? Is there some reason why you need to validate the path? – Helvick Aug 22 '10 at 16:33
up vote 3 down vote accepted

Windows maintains the current directory in the environment variable %CD%.

echo %CD%  
pushd c:\temp
echo %CD%
set X=%CD%
MyExe.exe %X%

will pass c:\temp to MyExe.exe

share|improve this answer
This isn't an environment variable; it's merely a "pseudo-variable". Whenever you use those, keep in mind to delete an actual variable of that name before as their magic doesn't work when a variable with that name exists. – Joey Aug 22 '10 at 17:11

The %CD% pseudo-environment variable contains the current working directory and is available within CMD\Batch files.

In your case a batchfile that just contains MyExe.exe %CD% will do what you want.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.