parse string using batch scipt
-
Friday, February 15, 2013 11:01 AM
Hi
Is it possible to search the string -Doracle_home= and the get the value from a command line of the process using batch script
C:\db\product\11.2.0\dbhome_1\jdk/bin/java -server -Xmx384M -XX:MaxPermSize=400M -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -DORACLE_HOME=C:\db\product\11.2.0\dbhome_1 -Doracle.home=C:\db\product\11.2.0\dbhome_1/oc4j -Doracle.oc4j.localhome=C:\db\product\11.2.0\dbhome_1\SLCAE205.us.oracle.com_db1569/sysman -DEMSTATE=C:\db\product\11.2.0\dbhome_1\SLCAE205.us.oracle.com_db1569 -Doracle.j2ee.dont.use.memory.archive=true -Djava.protocol.handler.pkgs=HTTPClientusing wmic i am able to get the commandline. Position of -Doracle_home varies for different process. So I cannot give Token in the for loop.
Thanks
Sreeja
All Replies
-
Friday, February 15, 2013 11:48 AM
It is possible but requires a set of nested tokenized for loops. Good Luck.
With PowerShell you can just use a RegEx expression and extract that single value:
-match '.*-DORACLE_HOME=(?<val>.*)\s'
That is close but I haven't tested it.
¯\_(ツ)_/¯
-
Friday, February 15, 2013 1:38 PMModerator
Try something like this ...
@echo off & setlocal EnableDelayedExpansion
:: For testing
set t=C:\db\product\11.2.0\dbhome_1\jdk/bin/java -server -Xmx384M -XX:MaxPermSize=400M -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -DORACLE_HOME=C:\db\product\11.2.0\dbhome_1 -Doracle.home=C:\db\product\11.2.0\dbhome_1/oc4j -Doracle.oc4j.localhome=C:\db\product\11.2.0\dbhome_1\SLCAE205.us.oracle.com_db1569/sysman -DEMSTATE=C:\db\product\11.2.0\dbhome_1\SLCAE205.us.oracle.com_db1569 -Doracle.j2ee.dont.use.memory.archive=true -Djava.protocol.handler.pkgs=HTTPClient
::
for /f "tokens=1-12 delims=-" %%a in ("%t%") do (
for %%? in (%%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l) do (
if !Next!==True set DORACLE_Home=%%? & goto :Found
if %%?==DORACLE_HOME set Next=True
)
)
echo Not found. & exit /b 1
:Found
echo.The value of DORACLE_HOME is %DORACLE_home%
Tom Lavedas
- Edited by Tom LavedasModerator Friday, February 15, 2013 1:50 PM to add a couple more tokens
-
Monday, February 18, 2013 6:58 AM
Thanks a lot..it worked.. one Question...
If the value to be prsed exceeds %%z...what is the next value?
-
Monday, February 18, 2013 10:38 AM
This worked... thanks
-------------------------------------------------------------------------
for /f "tokens=* delims=-" %%A in ("%t%") do (
-------------------------------------------------------------------------
for %%? in (%%A ) do (
echo test %%?
if !Next!==True set Ddomain.home=%%? & goto :Found
if %%?==-Ddomain.home set Next=True
)
)
echo Not found. & exit /b 1
:Found
echo.The value of Ddomain.home is %Ddomain.home%- Marked As Answer by Sreeja Mathew Monday, February 18, 2013 10:38 AM
-
Monday, February 18, 2013 2:14 PMModerator
OK, you make a good point, though I'm not certain you realize what that is - the outer FOR is not needed. This would suffice ...
@echo off & setlocal EnableDelayedExpansion
set t=C:\db\product\11.2.0\dbhome_1\jdk/bin/java -server -Xmx384M -XX:MaxPermSize=400M -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -DORACLE_HOME=C:\db\product\11.2.0\dbhome_1 -Doracle.home=C:\db\product\11.2.0\dbhome_1/oc4j -Doracle.oc4j.localhome=C:\db\product\11.2.0\dbhome_1\SLCAE205.us.oracle.com_db1569/sysman -DEMSTATE=C:\db\product\11.2.0\dbhome_1\SLCAE205.us.oracle.com_db1569 -Doracle.j2ee.dont.use.memory.archive=true -Djava.protocol.handler.pkgs=HTTPClient
set Next=False
for %%? in (%t%) do (
if !Next!==True set DORACLE.home=%%? & goto :Found
if /I %%?==-DORACLE.HOME set Next=True
)
echo Not found. & exit /b 1
:Found
echo.The value of DORACLE.HOME is %DORACLE.home%Note that I added the /I switch to the second IF statement to make the test case insensitive.
Also, I would note that your original request asked for the value of the "-Doracle_home=" parameter, not the "-Doracle.home=" parameter.
Tom Lavedas
- Proposed As Answer by OberwaldMicrosoft Community Contributor Monday, February 18, 2013 2:27 PM
- Marked As Answer by Sreeja Mathew Thursday, February 21, 2013 5:31 AM

