some executable, returns a string. Any idea how to set this string in to variable?. or recover string from terminal window??
I execute
Net time \\{ip for any computer}
Return:
Current time at \\{ip for any computer} is {date and time}
and set Date and time a variable this no promblem
Recover a string result from executable and set a variable
Moderator: DosItHelp
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Is this what you want?
Code: Select all
for /f %%a in ('Net time \\{ip for any computer}') do set your_var=%%a
Yeah its works......
Yeah Men, I luv u!!!!!!!
i got my data with:
example
-----------------
FOR /F "tokens=6*" %%A IN ('Net time \\{ip any computer}') DO set my_var=%%A %%B
Echo %my_var%
-----------------
today this resolved my problem
but if the execute had a result with many lines you can see only the last line.
if the last line had a less tokens than penultimate you can see the last words or tokens of penultimate lines.
-----------------------------------------------------------------------------------
for other poeple to wants resolve that
FOR /F
Syntax
FOR /F ["options"] %%parameter IN (filenameset) DO command
FOR /F ["options"] %%parameter IN ("Text string to process") DO command
Key
options:
delims=xxx The delimiter character(s) (default = a space)
skip=n A number of lines to skip at the beginning of the file.
(default = 0)
eol=; Character at the start of each line to indicate a comment
The default is a semicolon ;
tokens=n Specifies which numbered items to read from each line
(default = 1)
usebackq Specify `back quotes`:
- Use double quotes to quote long file names in filenameset.
- Use single quotes for 'Text string to process'
(useful if the text string contains double quotes)
Filenameset : A set of one or more files. Wildcards may be used.
If (filenameset) is a period character (.) then FOR will
loop through every file in the folder.
command : The command to carry out, including any
command-line parameters.
%%parameter : A replaceable parameter:
in a batch file use %%G (on the command line %G)
From: http://ss64.com/nt/for_f.html
i got my data with:
example
-----------------
FOR /F "tokens=6*" %%A IN ('Net time \\{ip any computer}') DO set my_var=%%A %%B
Echo %my_var%
-----------------
today this resolved my problem
but if the execute had a result with many lines you can see only the last line.
if the last line had a less tokens than penultimate you can see the last words or tokens of penultimate lines.
-----------------------------------------------------------------------------------
for other poeple to wants resolve that
FOR /F
Syntax
FOR /F ["options"] %%parameter IN (filenameset) DO command
FOR /F ["options"] %%parameter IN ("Text string to process") DO command
Key
options:
delims=xxx The delimiter character(s) (default = a space)
skip=n A number of lines to skip at the beginning of the file.
(default = 0)
eol=; Character at the start of each line to indicate a comment
The default is a semicolon ;
tokens=n Specifies which numbered items to read from each line
(default = 1)
usebackq Specify `back quotes`:
- Use double quotes to quote long file names in filenameset.
- Use single quotes for 'Text string to process'
(useful if the text string contains double quotes)
Filenameset : A set of one or more files. Wildcards may be used.
If (filenameset) is a period character (.) then FOR will
loop through every file in the folder.
command : The command to carry out, including any
command-line parameters.
%%parameter : A replaceable parameter:
in a batch file use %%G (on the command line %G)
From: http://ss64.com/nt/for_f.html
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Re: Yeah its works......
You can use a combination of "skip" and/or a goto statement to eliminate extra lines:jgamezu wrote:Yeah Men, I luv u!!!!!!!
i got my data with:
example
-----------------
FOR /F "tokens=6*" %%A IN ('Net time \\{ip any computer}') DO set my_var=%%A %%B
Echo %my_var%
-----------------
today this resolved my problem
but if the execute had a result with many lines you can see only the last line.
if the last line had a less tokens than penultimate you can see the last words or tokens of penultimate lines.
Code: Select all
for /f "tokens=6* skip=2" %%a in ('somecommand.cmd') do (
set something=%%a
)
The above will skip the first 2 lines of output and run the command on the rest of the lines of output.
Code: Select all
for /f "tokens=6*" %%a in ('someothercommand.cmd') do (
if %%a=="what we're looking for" (
set myvar=%%a
goto :continue
)
)
:continue
echo We broke out of the for loop
Ohhh, Yes it works
avery larry, I did my homework
thanks men with the help
for other people I have this code
thanks men with the help
for other people I have this code
Code: Select all
@echo off
SET count=0
FOR /f "tokens=*" %%G IN ('{your command}') DO (call :do_sums "%%G")
Echo %line_str%
pause
GOTO :eof
:do_sums
set /a count+=1
Rem ****compare with number of line you want***
IF !%count%!==!1! SET line_str=%1
GOTO :eof