我有一个字符串如下: -
此字符串是命令的输出,该命令在配置文件中查找所有服务条目并打印输出。 这里A B C等是服务和相应的服务入口或配置参数。
MAP(S): service.cfg OS_SERV 0 0 0 50 50 1 "D:\workdir\UPG_81\bin\olaunch" -f "D:\workdir\UPG_81\bin\osserv" GUI
SVR 0 0 1 99 99 2 "D:\workdir\UPG_81\bin\olaunch" -f "D:\workdir\UPG_81\bin\omf" -a netcap 0 1 1 1 1 60 "D:\workdir\UP
G_81\bin\netcap" netprobe 0 0 0 99 99 1 "D:\workdir\UPG_81\bin\netprobe" lamserv 1 1 1 1 1 10 "D:\workdir\UPG_81\
bin\lamserv" mserv 1 1 1 1 1 10 "D:\workdir\UPG_81\bin\mserv" uidserv 1 1 1 1 1 10 "D:\workdir\UPG_81\bin\uidser
v" rserv 0 1 1 1 1 10 "D:\workdir\UPG_81\bin\rserv" nlsserv 1 1 1 1 1 10 "D:\workdir\UPG_81\bin\nlsserv" om
fsvr 1 1 25 25 25 60 "D:\workdir\UPG_81\bin\objserv" -C 250 searchserv 0 0 0 12 12 10 "D:\workdir\UPG_81\bin\search" -
s searchserv notifserv 0 0 0 1 1 10 "D:\workdir\UPG_81\bin\notif" -C 250 notifservbroker 0 0 0 1 1 10 "D:\workdir
\UPG_81\bin\eventqb" -s notifservbroker mloader 1 1 1 1 1 10 "D:\workdir\UPG_81\bin\mloader" postserv 0 1 1 3 3 1
0 "D:\workdir\UPG_81\bin\post" -h advancerserv 0 0 0 3 3 10 "D:\workdir\UPG_81\bin\advancer" -C 250 advancerserv
broker 0 0 0 1 1 10 "D:\workdir\UPG_81\bin\eventqb" -s advancerservbroker scheduleserv 0 1 1 1 1 10 "D:\workdir\UPG_81
\bin\schedule" registry 0 1 1 1 1 10 "D:\workdir\UPG_81\bin\rgyserv" repserv 0 0 0 0 0 10 "D:\workdir\UPG_81\bin\
replic8r" repservbroker 0 0 0 1 1 10 "D:\workdir\UPG_81\bin\eventqb" -s repservbroker cacheserv 0 1 1 1 1 10 "D:\
workdir\UPG_81\bin\cachesche" -C 250 eventlogger 0 0 1 1 1 10 "D:\workdir\UPG_81\bin\eventlogger" -s expireserv 0
0 1 1 1 10 "D:\workdir\UPG_81\bin\expire" partEOLserv 0 0 1 1 1 10 "D:\workdir\UPG_81\bin\partEOL" -R 90 msqlpdm
m81dm 0 0 25 25 25 2 "D:\workdir\UPG_81\bin\msqlora" -sn D:\workdir\UPG_81\config\pdmm81dm.pwf -C 5000 mgrsvr 0 0 1 1
1 10 "D:\workdir\UPG_81\bin\mgrora"
我想使用java从此字符串中获取D:\workdir\UPG_81\config\pdmm81dm.pwf
服务msqlpdmm81dm
,此密码文件云使用-s,-n或-sn选项。
请提出一个更好的方法。
这个代码工作得很好,
cfgtest是我的实用程序,它解析配置文件并从配置文件中返回特定条目。
Process p = _executeProcess("cfgtest","-m","service.cfg");
BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
String s = br.readLine();
while ( s != null )
{
if ( s.matches( "^\\s*msql.*$" ) )
{
StringTokenizer st = new StringTokenizer( s, " " );
while ( st.hasMoreTokens() )
{
if ( st.nextToken().equals( "-sn" ) )
{
pwf = st.nextToken();
}
}
}
s = br.readLine();
}
br.close();
但是现在我改变方法并尝试使用一些函数将cfgtest命令输出作为单个字符串返回。
String cmd = "cfgtest -m service.cfg";
int dstat = shell._execCommand(cmd);
String s = null;
s = shell._getCommandOutput();
System.out.println(s);