directing output of exe to variable

Apr 4, 2010
5
0
Hi,

I have managed to capture the output of program mediachanger.exe as follows

for /f "usebackq delims=" %i in (`mediachanger unmount`) do set changer_reply=%i

unfortunately some of the output from mediachanger is over multiple lines as follows

000: full
001: full
002: full
003: full
004: full
005: full
006: full
007: full

I would like to red each line into a different variables

eg n1 = 000: full
n2 = 001: full

Have been unable to do this. I would be gratefull for any help

Oh by the way I have very little expierence writing code
 
May 20, 2008
11,297
95
Syracuse, NY, USA
Not tested much but has some basic functionality:

Code:
v:\> set j=0 & for /f "usebackq delims=" %i in (`echo foo^r^nbar^r^ndog^r^ncat`) do (set line%j=%i & set j=%@inc[%j])

v:\> set line*
line0=foo
line1=bar
line2=dog
line3=cat
It looks better in a batch file using DO.

Code:
v:\> type dodo.bat
set i=0
do line in /p ping ilucky
        iff "%line" NE "" then
                set line%i=%line
                set i=%@inc[%i]
        endiff
enddo

v:\> dodo.bat

v:\> set line*
line=
line0=Pinging lucky.syr.edu [128.230.13.36] with 32 bytes of data:
line1=Reply from 128.230.13.36: bytes=32 time=43ms TTL=117
line2=Reply from 128.230.13.36: bytes=32 time=41ms TTL=117
line3=Reply from 128.230.13.36: bytes=32 time=41ms TTL=117
line4=Reply from 128.230.13.36: bytes=32 time=43ms TTL=117
line5=Ping statistics for 128.230.13.36:
line6=    Packets: Sent = 4, Received = 4, Lost = 0 (0 loss),
line7=Approximate round trip times in milli-seconds:
line8=    Minimum = 41ms, Maximum = 43ms, Average = 42ms
Hi,

I have managed to capture the output of program mediachanger.exe as follows

for /f "usebackq delims=" %i in (`mediachanger unmount`) do set changer_reply=%i

unfortunately some of the output from mediachanger is over multiple lines as follows

000: full
001: full
002: full
003: full
004: full
005: full
006: full
007: full

I would like to red each line into a different variables

eg n1 = 000: full
n2 = 001: full

Have been unable to do this. I would be gratefull for any help

Oh by the way I have very little expierence writing code
 
Apr 4, 2010
5
0
Vince thanks for the reply bit I tried dodo.bat and it returns no output only get
c:\batch\dodo.bat
set i=0
do line in /p ping ilucky


I tried ping ilucky and do get an output from this command
 
May 20, 2008
11,297
95
Syracuse, NY, USA
I doubt "ping ilucky" would return useful results for you since "ilucky" is an
alias. If it's returning error messages (stderr) you won't capture them. Try
pinging a **real** computer (like lucky.syr.edu).

On Tue, 06 Apr 2010 08:37:22 -0400, jolly1 <> wrote:

|Vince thanks for the reply bit I tried dodo.bat and it returns no output only get
|c:\batch\dodo.bat
|set i=0
|do line in /p ping ilucky
|
|
|I tried ping ilucky and do get an output from this command
|
|
|
|
--
- Vince
 
Apr 4, 2010
5
0
Vince still no joy

here is the file

set i=0
do line in /p ping lucky.syr.edu
iff "%line" NE "" then
set line%i=%line
set i=%@inc[%i]

endiff
enddo
exit

here is the output
set i=0
do line in /p ping lucky.syr.edu
exit

tried as dodo.bat and dodo.btm same result
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,426
85
Albuquerque, NM
prospero.unm.edu
set i=0
do line in /p ping lucky.syr.edu
iff "%line" NE "" then
set line%i=%line
set i=%@inc[%i]

endiff
enddo
exit

Note that PING's output contains redirection characters, so it probably isn't the best utility to test with.... For starters, you could change

Code:
set line%i=%line

to

Code:
set line%i="%line"

to better handle the less-than signs. You should also remove the EXIT line; that exits the shell, losing all the environment variables you have just created.
 
G

Glennbo51

Guest
On 04/06/2010 10:21, jolly1 wrote:

> Vince still no joy
>
> here is the file
>
> set i=0
> do line in /p ping lucky.syr.edu
> iff "%line" NE "" then
> set line%i=%line
> set i=%@inc[%i]
>
> endiff
> enddo
> exit
>
> here is the output
> set i=0
> do line in /p ping lucky.syr.edu
> exit
>
> tried as dodo.bat and dodo.btm same result
>
>
>
>
>
>
This is the output environment variables I got when when I ran the above
BAT files

lineline0=Pinging lucky.syr.edu [128.230.13.36] with 32 bytes of data:
line1=Reply from 128.230.13.36: bytes=32 time=71ms TTL=118
line2=Reply from 128.230.13.36: bytes=32 time=74ms TTL=118
line3=Reply from 128.230.13.36: bytes=32 time=77ms TTL=118
line4=Reply from 128.230.13.36: bytes=32 time=74ms TTL=118
line5=Ping statistics for 128.230.13.36:
line6= Packets: Sent = 4, Received = 4, Lost = 0 (0 loss),
line7=Approximate round trip times in milli-seconds:
line8= Minimum = 71ms, Maximum = 77ms, Average = 74ms

Is that what you expected? Nothing output to screen though
 
Apr 4, 2010
5
0
Hi success at last, when the last post indicating all Ok. Tried again.

and success

@echo off
set i=0
do line in /p mediachanger fullslots
iff "%line" NE "" then
set line%i="%line"
set i=%@inc[%i]

endiff
enddo
echo %line1%
echo %line2%
echo %line3%
echo %line4%
echo %line5%
echo %line6%
echo %line7%
echo %line8%

this time all variables listed output

thanks a lot for all the help
 
May 20, 2008
3,515
4
Elkridge, MD, USA
| @echo off
| set i=0
| do line in /p mediachanger fullslots
| iff "%line" NE "" then
| set line%i="%line"
| set i=%@inc[%i]
|
| endiff
| enddo
| echo %line1%
| echo %line2%
| echo %line3%
| echo %line4%
| echo %line5%
| echo %line6%
| echo %line7%
| echo %line8%

Here is a simpler version (and safer, too - leftover variables are deleted
first):

--- begin code ---
@echo off
setlocal
unset i line*
do line in /p mediachanger fullslots
iff defined line then
set i=%@inc[%i]
set line%i=%@safeenv[%line]
endiff
enddo
for /l %n in (1,1,%i) echo %@format[3,%n] %[line%n]
--- end code ---

This utilizes the TCC feature that the arithmetic value of an undefined
variable is 0, and the @SAFEENV function from Charles Dye's plugin
SAFECHARS.DLL, which converts characters significant to the parser to
characters with the same visible representation but not affecting the
parser.
--
Steve
 

samintz

Scott Mintz
May 20, 2008
1,489
15
Solon, OH, USA
Why can't you use the new @execarray or @filearray functions?

unsetarray /q line
mediachanger fullslots > foo.$$$
setarray line[%@inc[%@lines[foo.$$$]]]
set num_slots=%@filearray[line,foo.$$$]
del /q foo.$$$
do i = 0 to %num_slots
echo "%line[%i]"
enddo

Or alternatively, if you know how many lines there are:

unsetarray /q line
setarray line[200]
echo %@execarray[line,mediachanger fullslots] >& nul
echo %line[0]
echo %line[1]
etc.

The caveat is that array functions and variables are not available in the
TCC/LE version.

-Scott

Steve F$BaC(Bi$BaO(B <> wrote on 04/06/2010 04:59:28 PM:


> | @echo off
> | set i=0
> | do line in /p mediachanger fullslots
> | iff "%line" NE "" then
> | set line%i="%line"
> | set i=%@inc[%i]
> |
> | endiff
> | enddo
> | echo %line1%
> | echo %line2%
> | echo %line3%
> | echo %line4%
> | echo %line5%
> | echo %line6%
> | echo %line7%
> | echo %line8%
>
> Here is a simpler version (and safer, too - leftover variables are
deleted

> first):
>
> --- begin code ---
> @echo off
> setlocal
> unset i line*
> do line in /p mediachanger fullslots
> iff defined line then
> set i=%@inc[%i]
> set line%i=%@safeenv[%line]
> endiff
> enddo
> for /l %n in (1,1,%i) echo %@format[3,%n] %[line%n]
> --- end code ---
>
> This utilizes the TCC feature that the arithmetic value of an undefined
> variable is 0, and the @SAFEENV function from Charles Dye's plugin
> SAFECHARS.DLL, which converts characters significant to the parser to
> characters with the same visible representation but not affecting the
> parser.
> --
> Steve
>
>
>
>
 
Similar threads
Thread starter Title Forum Replies Date
A How to? TEE - duplicate output to STDERR Support 3
FreezerBurnt ANSI Prompt messes up list output. Support 39
Ó Recent git output not shown on TCC Support 1
Peter Murschall TEE cannot handle Unicode output Support 2
C TEE command appending null characters to output Support 6
Jesse Heines webform output different in ver. 26 than ver. 25 Support 2
vefatica Piping the output of a DO loop. Support 4
vefatica TCMD output invisible on Win10 Support 22
B How can TCC make an output as a part of command string Support 2
Enigma Take Command 23 duplicates output Support 0
Joe Caverly Works with CMD.EXE, no output with TCC.EXE Support 7
S Output from debugger Support 4
M TCC incorrect dir output since Windows 1803 Support 6
A WAD Output redirection to IF block fails with "unbalanced brackets" Support 7
P Scrollable colored output Support 3
scottb How to? ipconfig output in current window Support 4
David McClelland TEE command puts it's output file in c:\ Support 4
vefatica How to? TPIPE ... see output right away? Support 4
T Fixed Unnecessary debug output Support 3
JohnQSmith Weird DIR output (missing lines) Support 1
J WAD Output redirection in tcexit looses data Support 31
vefatica Console output slower that before Support 8
Mordachai How to capture all console output from a TCMD session? Support 4
C Output continues after Ctrl-Break Support 8
Steve Pitts WAD Strange output from DEL of a non-existent directory Support 7
I perl output is not visible Support 4
I v16 - cls corrupts output stream Support 7
D Fixed Minor problem: output not alligned in the tree command Support 1
vefatica WAD IDE, output window to foreground Support 3
R WAD Strange output from "memory" command Support 1
A How to? Set up a log file for all command output Support 3
A How to? Use TEE with .NET output Support 6
T How to? Logging Output from External Programs Support 4
Frank output of @ipaddress/@ipname Support 1
dcantor Unidentifiable output Support 16
Stefano Piccardi forum software writes debugging output Support 5
Stefano Piccardi TCC 13 vs. TCC 14 different FFIND /E"d$" output Support 1
H TPIPE: /FILTER and /OUTPUT unexpected incompatibility Support 6
Stefano Piccardi issue: redirecting GOSUB output Support 11
A How to? Pass output from ffind to another command in a BTM file Support 5
J Can you redirect output to printer device with echo? Support 1
A How to? How to enable UTF-8 output in tcmd.ini Support 9
W Ascii character output Support 12
S SELECT DEL (*D.DLL) - output curious Support 8
T eval[] crashes with negative binary output Support 1
E Redirect output from "start"-ed console Support 5
E Scrolling output to single, non-scrolling line Support 13
A Redirecting TCC output to a different RDP Session Support 6
D Start program without waiting and redirect output Support 6
vefatica ZIP's informative output Support 1

Similar threads