Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: DOS question

  1. #1
    Junior Member
    Join Date
    Aug 2003
    Posts
    11

    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?
    Everything Turns Grey!

  2. #2
    Senior Member
    Join Date
    Nov 2001
    Posts
    4,785
    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.’”

  3. #3
    Junior Member
    Join Date
    Aug 2003
    Posts
    11
    Nothing really in particualr, I was just experimenting with it.
    Everything Turns Grey!

  4. #4
    Senior Member
    Join Date
    Nov 2001
    Posts
    4,785
    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.’”

  5. #5
    Junior Member
    Join Date
    Aug 2003
    Posts
    11
    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?
    Everything Turns Grey!

  6. #6
    Senior Member Maestr0's Avatar
    Join Date
    May 2003
    Posts
    604
    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

  7. #7
    Junior Member
    Join Date
    Oct 2003
    Posts
    14
    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

  8. #8
    Senior Member
    Join Date
    Oct 2003
    Posts
    107
    nice info 10x i didnt know that

  9. #9
    Senior Member
    Join Date
    Nov 2001
    Posts
    4,785
    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.’”

  10. #10
    Junior Member
    Join Date
    Aug 2003
    Posts
    11
    For /F “tokens=3” %X in (results.txt) do set MyVar = %X

    what does the "/f" and "tokens=3" exactly do?
    Everything Turns Grey!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •