Friday, January 28, 2011

WHICH statement for Windows

Ok... I know... Not really an ADF post...
But yesterday I got the question 'Which sqlplus is executed?'
The answer was: e:\app\ses\bin\sqlplus.exe
The return question was 'Are you sure it is??'
Lucky for me, I'm positive that there is only one copy of sqlplus.exe on the machine, as SES (Oracle Secure Enterprise Search) is the only product with an Oracle Client with it...

But what if you're not sure?
With Linux you get a nice little utility called which.
By calling which you get the location of the executable that will be executed if you would run

Windows does not have that utility... yet...
If you create the following batch (or command) file and place it somewhere in your path you do have that utility.

Paste the following code into which(.cmd):
@for %%i in ( %1 ) do @echo. %%~$PATH:i

When you enter which sqlplus.exe you'll see something like:

H:\>which sqlplus.exe

See, I was right... e:\app\ses\bin\sqlplus.exe was executed...
This also works with non-executables:

H:\>which orauts.sym

Drawback: You need to include the extension. So if the file you look for opmnctl and you do not know the extension, you might need to search for opmnctl.exe, opmnctl.cmd and opmnctl.bat

Happy searching!

1 comment:

  1. When I do:

    Start > Run > sqlplus

    The window has the sqlplus path as title!