China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-31 20:15
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Looking for methods for batch processing to accept the return results of scripting languages! View 2,632 Replies 26
Floor 16 Posted 2006-11-08 00:22 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
That is to say, the for statement is to find in the information output by C:\bea\weblogic91\common\bin\wlst.cmd startserver.py, not what I want to find the variable status in startserver.py and get the value of status, right?
Floor 17 Posted 2006-11-08 00:32 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
for /f %%i in (.......The way you get information: what command or file to execute to get the output.....) do what you want to do with the information obtained by for

So, the for statement is in for /f %%i in (here execute what to get the output information to find)……

This is what Brother electronixtar on the 3rd floor said about the ways to obtain variables from any of the following:
                1. Temporary file
                2. Parameter
                3. Variable
                4. Output redirection

You can get the information (or the variable value you want to obtain) through the for ....(information acquisition approach interface) do ... this method~:)

Since the above several methods can let you get the information (or the variable value you want to obtain),
Then how to obtain the information you want depends on how the information provider (the command or program that provides you with the information) cooperates with your batch processing~:)


Ways to obtain information: (Note: The first, third, and fourth methods to obtain variables)

) The content to be obtained is in the a.txt file, you can treat it as a temporary file (the first type).
  This temporary file can be created with any application and script.

) set /p variable name= assignment statement, get the content of the first line of the a.txt text through <a.txt redirection.
  This is also a way to obtain (exchange) variables.


C:\TEMP\put>type a.txt
My name is Redtek~:)

C:\TEMP\put>set /p 我的名字=<a.txt

C:\TEMP\put>echo %我的名字%
My name is Redtek~:)


[ Last edited by redtek on 2006-11-8 at 12:41 AM ]
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 18 Posted 2006-11-08 01:09 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Now I use the statement `for /f "skip=34 delims=" %%i in ('C:\bea\weblogic91\common\bin\wlst.cmd startserver.py') do echo %%i` to find.

`C:\bestway\jcl>echo RUNNING`
RUNNING

`C:\bestway\jcl>echo C:\bestway\jcl>ENDLOCAL`
C:\bestway\jcl>ENDLOCAL

Among them, `RUNNING` is the value I got by using `print status` in `startserver.py`, which should be what I want. But the two results found are `RUNNING` and `C:\bestway\jcl>ENDLOCAL`. Then which one is stored in the variable `%i`? Is it the latter?
Floor 19 Posted 2006-11-08 01:12 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Is it that adding set state= after the for statement assigns the variable %i to state, that is, now state is RUNNING or C:\bestway\jcl>ENDLOCAL
Floor 20 Posted 2006-11-08 01:32 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Simulated to build a multi-line data file a.txt (representing the output information containing the string RUNNING that you want to retrieve)


C:\TEMP\put>type a.txt
a
b
c
d
e
f
g

You see that a.txt above has multiple lines, and the last line is g.

Directly obtain the multi-line content of a.txt on the command line and assign it to a variable named "variable".


C:\TEMP\put>for /f %i in (a.txt) do set 变量=%i
(Notice carefully: The above line of command is executed. The following outputs are the assignment process when the above for is executed:)
 C:\TEMP\put>set 变量=a
 C:\TEMP\put>set 变量=b
 C:\TEMP\put>set 变量=c
 C:\TEMP\put>set 变量=d
 C:\TEMP\put>set 变量=e
 C:\TEMP\put>set 变量=f
 C:\TEMP\put>set 变量=g

You see that when the for is executed, it successively assigns the content obtained from a.txt to the variable.
Because it is assigned to the same variable multiple times, so the last sentence: set 变量=g has "erased" the previous assigned values, all replaced by the character g.


C:\TEMP\put>echo %变量%
g

The above shows the content of the variable, and the result is the last obtained content: g

So, the valid output you get from the for assignment in sequence is only the last line.
So, for ...skip=skipping lines can solve the content of a specified line when the number of fixed output lines remains unchanged.
So, if == can also solve the situation of accurately matching and finding whether the content you are looking for is in %%i without assignment.

But, it seems that I remember a post where you once wanted to judge whether the Weblogic server was running normally.
If this post is related to the post mentioned above regarding judging whether the Weblogic server starts normally,
then you are taking a very big detour by doing this.
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 21 Posted 2006-11-08 01:46 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Yes, the previous post, I used netstat -na | findstr ":80 " to judge whether Weblogic started successfully. But later my superior said to implement the judgment of whether it started in the script. So now I'm trying every way to get the judgment result of the script. There's no way. But I want the result of RUNNING, but now the value of %%i is C:\bestway\jcl>ENDLOCA. Can I delete C:\bestway\jcl>ENDLOCA?
Floor 22 Posted 2006-11-08 02:58 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
This is to find whether there is the specified string value in the output information obtained through for..()... It can be replaced with the content you specify such as RUN...

(The following code is just the principle. Brother sunyao can rewrite more suitable content specifically: )
(In the code, if is an exact match regardless of case. If fuzzy matching is needed, methods like find or findstr or character replacement can be used)


@echo off

set server_status=Not started
for /f %%i in (a.txt) do (
if /i == ( set server_status=Started )
)

echo %server_status%
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 23 Posted 2006-11-08 03:17 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
for /f "skip=34 delims=" %%i in ('C:\bea\weblogic91\common\bin\wlst.cmd startserver.py') do (
if /i "%i"=="RUNNING" ( set state="RUNNING" )
)
I'll try if it works
Floor 24 Posted 2006-11-08 04:37 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Tried it, success!!!
Thanks to brother redtek!!!
Let's see if there are any other issues
It's okay, just start making the stop script
Floor 25 Posted 2006-11-16 20:28 ·  美国 科罗拉多州 阿拉珀霍 利特尔顿 TW_Telecom控股股份有限公司
初级用户
Credits 35
Posts 18
Joined 2006-04-26 13:31
20-year member
UID 54481
Status Offline
Learning
Floor 26 Posted 2006-11-23 00:44
中级用户
★★
DOS之日
Credits 337
Posts 161
Joined 2006-11-04 05:27
19-year member
UID 69523
Gender Male
Status Offline
I was just looking for this
for /f %%h in (`echo hxuan`) do for /f %%x in (`echo hxuan`) do if %%h==%%x nul
Floor 27 Posted 2006-11-23 07:20 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
People are already discussing WebLogic. That's high-tech.

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Forum Jump: