Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
popd
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

2 Answers 2

up vote 3 down vote accepted

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

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

will pass c:\temp to MyExe.exe

share|improve this answer
1  
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

 
discard

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.