4

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?

Ohad Horesh
  • 249
  • 2
  • 4
  • 7
  • 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 Answers2

9

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

user9517
  • 115,471
  • 20
  • 215
  • 297
  • 2
    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
5

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.

Helvick
  • 20,019
  • 4
  • 38
  • 55