-
October 14th, 2003, 08:15 PM
#1
DOS question
I'm pretty new to programming, and had a question about DOS. How do you pipe output from a command to a variable?
-
October 14th, 2003, 08:42 PM
#2
what command in particular are you talking about?
Bukhari:V3B48N826 “The Prophet said, ‘Isn’t the witness of a woman equal to half of that of a man?’ The women said, ‘Yes.’ He said, ‘This is because of the deficiency of a woman’s mind.’”
-
October 14th, 2003, 08:43 PM
#3
Nothing really in particualr, I was just experimenting with it.
-
October 14th, 2003, 09:35 PM
#4
If your talking about bat type programming output can be piped to a file and used from there. The output of most programs is to cluttered to use as a var.
U:\>ping -n 1 yahoo.com
Pinging yahoo.com [66.218.71.198] with 32 bytes of data:
Reply from 66.218.71.198: bytes=32 time=70ms TTL=243
Ping statistics for 66.218.71.198:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 70ms, Maximum = 70ms, Average = 70ms
So you have to trim it.
C:\>ping -n 1 yahoo.com |find "Reply" results.txt
In results.txt you’ll have:
Reply from 66.218.71.198: bytes=32 time=70ms TTL=243
Still more info then you can deal with so:
For /F “tokens=3” %X in (results.txt) do set MyVar = %X
(when used in a bat file %X needs to be written %%X)
On entering “set” at a prompt you’ll see MyVar = 66.218.71.198:
You have to deal with the info that’s output depending on the type of output you have and the type of input you need. That’s why I asked for what proggie.
Bukhari:V3B48N826 “The Prophet said, ‘Isn’t the witness of a woman equal to half of that of a man?’ The women said, ‘Yes.’ He said, ‘This is because of the deficiency of a woman’s mind.’”
-
October 15th, 2003, 12:32 AM
#5
Thank you! Just one more question. Le'ts just say you wanted to pipe DIR into a var.
dir|set dir1
could you use something like that for the syntax?
-
October 15th, 2003, 04:29 AM
#6
If you want to save all the output from a command use a redirect instead of a pipe. Like "dir > listing.txt" this will redirect the output to the file named listing.txt
-Maestr0
\"If computers are to become smart enough to design their own successors, initiating a process that will lead to God-like omniscience after a number of ever swifter passages from one generation of computers to the next, someone is going to have to write the software that gets the process going, and humans have given absolutely no evidence of being able to write such software.\" -Jaron Lanier
-
October 15th, 2003, 07:33 AM
#7
Junior Member
Pipes are connections between two programs or two commands or a program and a command. Pipes allow the output of one program to be redirected as the input for a second program.
The DOS symbol for a pipe is the vertical bar ( | ). To redirect the output of one command to another type the name of the first command, followed by a vertical bar, followed by the name of the second command.
for example
dir | find "03"
dir | more
-
October 15th, 2003, 02:55 PM
#8
Senior Member
nice info 10x i didnt know that
-
October 15th, 2003, 03:50 PM
#9
No or at least i dont know of a way to load an array into memory using just DOS commands. you could using c/cpp, perl etc, but you would need the program itself to call the array from the program. Basic can load a listing like that into a var but again it would need to be called from inside the program. i suppose you could parse each line into a env. var of its own and call them all but that seems like more trouble than its worth
Bukhari:V3B48N826 “The Prophet said, ‘Isn’t the witness of a woman equal to half of that of a man?’ The women said, ‘Yes.’ He said, ‘This is because of the deficiency of a woman’s mind.’”
-
October 15th, 2003, 09:02 PM
#10
For /F “tokens=3” %X in (results.txt) do set MyVar = %X
what does the "/f" and "tokens=3" exactly do?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|