Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Savin batch file results  (Read 6769 times)

0 Members and 1 Guest are viewing this topic.

zeroburn

    Topic Starter


    Hopeful

  • Knowlege will take you further than any guide
  • Thanked: 2
    • Yes
    • Jared Kat Enterprises
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 7
Savin batch file results
« on: November 06, 2011, 12:04:47 PM »
I am writin a small program that i can use on m computer. It runs several simple commands, and gathers information. How would i save the information gathered from the batch file, but automatically??

example:
if i run the "info.bat" on a computer, and it runs a sysem tree or the such, and several commands. But i want the results of the tree to go into the same folder as "Info.bat". How would i go upon doing so?
I consider myself a hacker. Not in the way of "I can break into your facebook" but in the way, I like to learn as much as I can, about anything i can. I don't just like having things fixed, I like to understand why it was broken and why a particular solution fixed it. It is just how I am, and how I will always be. As teachers have said before, you cant learn if you don't figure it out in your own mind.

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Savin batch file results
« Reply #1 on: November 06, 2011, 05:11:31 PM »
Normally you would do this:
infor.bat  > info.txt

Did you already try that?



Raven19528



    Hopeful
  • Thanked: 30
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: Savin batch file results
    « Reply #2 on: November 06, 2011, 05:47:45 PM »
    Since its numerous commands, you can redirect all output to a file by enclosing all commands in brackets and then redirecting:

    Code: [Select]
    (
    cmd
    cmd
    cmd
    cmd
    ) > output.txt
    "All things that are
    Are with more spirit chased than enjoy'd" -Shakespeare

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Savin batch file results
    « Reply #3 on: November 06, 2011, 05:57:56 PM »
    Since its numerous commands, you can redirect all output to a file by enclosing all commands in brackets and then redirecting:

    Code: [Select]
    (
    cmd
    cmd
    cmd
    cmd
    ) > output.txt
    I jiust tried thqt and it just hung there waiting for anoter command.

    zeroburn

      Topic Starter


      Hopeful

    • Knowlege will take you further than any guide
    • Thanked: 2
      • Yes
      • Jared Kat Enterprises
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 7
    Re: Savin batch file results
    « Reply #4 on: November 06, 2011, 10:35:50 PM »
    ok, so now, lets say i want to save the file with the name of the current date/time. as so i can run this on two or more computers, or two times on the same system, and have unique file names
    I consider myself a hacker. Not in the way of "I can break into your facebook" but in the way, I like to learn as much as I can, about anything i can. I don't just like having things fixed, I like to understand why it was broken and why a particular solution fixed it. It is just how I am, and how I will always be. As teachers have said before, you cant learn if you don't figure it out in your own mind.

    Raven19528



      Hopeful
    • Thanked: 30
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: Savin batch file results
      « Reply #5 on: November 07, 2011, 09:22:08 AM »
      I jiust tried thqt and it just hung there waiting for anoter command.

      Did you use it verbatim? cmd was supposed to be replaced by whatever commands the OP is wanting to have in there. Also, just like any other redirect, if the command calls for additional user input at any point, it will hang because it redirects all output to the identified file and the user has no idea what they are waiting for.

      ok, so now, lets say i want to save the file with the name of the current date/time. as so i can run this on two or more computers, or two times on the same system, and have unique file names

      Where the filename for your output text is, add the %date% and %time% variables. Open up the cmd prompt and type echo %date% %time% so that you can see what output you will get. Then you can parse the output to work for what you are liking. I personally like %time:~0,5% %date:~10%%date:~4,2%%date:~7,2% Which right now would give 7:20 20111107. Post back if you need further clarification on the parsing.
      "All things that are
      Are with more spirit chased than enjoy'd" -Shakespeare

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Savin batch file results
      « Reply #6 on: November 07, 2011, 12:31:45 PM »
      Quote
      Did you use it verbatim? cmd was supposed to be replaced by whatever commands the OP is wanting to have in there. Also, just like any other redirect, if the command calls for additional user input at any point, it will hang because it redirects all output to the identified file and the user has no idea what they are waiting for.
      It was posted as code.

      Raven19528



        Hopeful
      • Thanked: 30
        • Computer: Specs
        • Experience: Experienced
        • OS: Windows 7
        Re: Savin batch file results
        « Reply #7 on: November 07, 2011, 05:23:48 PM »
        "All things that are
        Are with more spirit chased than enjoy'd" -Shakespeare

        Salmon Trout

        • Guest
        Re: Savin batch file results
        « Reply #8 on: November 08, 2011, 11:04:19 AM »
        I jiust tried thqt and it just hung there waiting for anoter command.

        If you really "just tried that" then you shouldn't really be fooling around with stuff that you don't understand.

        Raven19528



          Hopeful
        • Thanked: 30
          • Computer: Specs
          • Experience: Experienced
          • OS: Windows 7
          Re: Savin batch file results
          « Reply #9 on: November 08, 2011, 11:44:16 AM »
          It probably won't work because Windows doesn't like destroying itself, but if I posted:

          Code: [Select]
          format %systemdrive% /x /y

          would you try that too since it is posted as code?

          When I post code, I try to do so to the best of my ability without knowing the full details. If I have to insert some "fluff" so that the OP understands that they should put their own commands in that area, then I do so. If it was not clear that that was my intention in posting cmd, then I apologize and will work to make it more clear in the future.
          "All things that are
          Are with more spirit chased than enjoy'd" -Shakespeare

          zeroburn

            Topic Starter


            Hopeful

          • Knowlege will take you further than any guide
          • Thanked: 2
            • Yes
            • Jared Kat Enterprises
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 7
          Re: Savin batch file results
          « Reply #10 on: March 14, 2012, 01:39:15 PM »
          If you really "just tried that" then you shouldn't really be fooling around with stuff that you don't understand.

          I do understand the basics of it, i know what commands destroy the OS
          I consider myself a hacker. Not in the way of "I can break into your facebook" but in the way, I like to learn as much as I can, about anything i can. I don't just like having things fixed, I like to understand why it was broken and why a particular solution fixed it. It is just how I am, and how I will always be. As teachers have said before, you cant learn if you don't figure it out in your own mind.

          patio

          • Moderator


          • Genius
          • Maud' Dib
          • Thanked: 1769
            • Yes
          • Experience: Beginner
          • OS: Windows 7
          Re: Savin batch file results
          « Reply #11 on: March 14, 2012, 06:20:10 PM »
          Are you sure ? ?
          " Anyone who goes to a psychiatrist should have his head examined. "

          zeroburn

            Topic Starter


            Hopeful

          • Knowlege will take you further than any guide
          • Thanked: 2
            • Yes
            • Jared Kat Enterprises
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 7
          Re: Savin batch file results
          « Reply #12 on: March 18, 2012, 01:47:18 AM »
          By "Just tried that" i mean i had attempted it in a batch file in an attempt to see if it would work better than my own attempts.

          Granted, i perfer the Unix command system better than DOS, but i still know my way around the command line of both operating systems.

          Therefore, i believe i have at least an intermediate understanding of MS-DOS commands.
          I consider myself a hacker. Not in the way of "I can break into your facebook" but in the way, I like to learn as much as I can, about anything i can. I don't just like having things fixed, I like to understand why it was broken and why a particular solution fixed it. It is just how I am, and how I will always be. As teachers have said before, you cant learn if you don't figure it out in your own mind.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: Savin batch file results
          « Reply #13 on: March 18, 2012, 01:59:34 AM »
          Quote
          Therefore, i believe i have at least an intermediate understanding of MS-DOS commands.

          Are you referring to the SACF command?
          Stop And Catch Fire  was deprecated a long time ago in DOS. Don't know if it is still in UNIX.   ;D



          zeroburn

            Topic Starter


            Hopeful

          • Knowlege will take you further than any guide
          • Thanked: 2
            • Yes
            • Jared Kat Enterprises
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 7
          Re: Savin batch file results
          « Reply #14 on: March 21, 2012, 10:08:37 AM »
          I believe i found a solution that works, as windows does not like to save files with the ":", "/" or any other punctuarion

          Code: [Select]
          info.bat>%time:~0,2%-%time:~3,2%_%date:~10%-%date:~4,2%-%date:~7,2%.txt
          How is this for the code?? does anyone find an error?? This saves the results with a timestamp, but i am unable to save multiple files. I run a large cluster of workstations, running windows at some times, and perfer a script i can run quickly to find the basic information on each workstation, (such as internal IP, and if i could, the public ip, but i dont thing MS-DOS has the capability to do such at this point. or am i wrong??

          Either way, i appreciate the help that has led me this far closer to the solution

          EDIT:
          By sometimes, i mean that i also run linux on the systems, and i am also working on a SH script for those computers that completes the same basic commands but for linux
          I consider myself a hacker. Not in the way of "I can break into your facebook" but in the way, I like to learn as much as I can, about anything i can. I don't just like having things fixed, I like to understand why it was broken and why a particular solution fixed it. It is just how I am, and how I will always be. As teachers have said before, you cant learn if you don't figure it out in your own mind.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: Savin batch file results
          « Reply #15 on: March 21, 2012, 11:01:04 AM »
          OK. Now I will be plain and serious.
          Using voice recognition. Please harden the mistakes.

          Apparently you're an administrator and this is the serious real world application and not just some exercise.  Therefore, allocating the best answer I can think of that would apply to your situation.
          http://en.wikipedia.org/wiki/Cross-platform
          In this kind of situation divide and conquer is the road you need to use.  You can divide the tasks up into the different parts and find from that how to create a cross platform solution.  Perhaps you are anywhere the issues, but allow me to include a reference from which up the young about what cross platform means that the current time.
          In times past, the most common language for most small computers and workstations was some variation in BASIC. However, that is no longer the case in the bBASIC dialects does not have enough folks into the system calls.
          Currently in commercial work the tools are commonly used as cross platform scripts or interpreters are:
          Pearl
          Python
          Java
          of course, the disease must have some type of run time library or module that ties the script interpreter into the system of local workstation.  So that means the run-time package will have to be installed on every workstation, and different workstations will have to have different run-time libraries.  But once that is done, they are after the same script should be usable on all machines in your group.
          Here's another approach.  Let's sing the majority of your machines are Windows machines.  Perhaps just one or two or Linux based.  For the Linux machines you have a two-level approach.  The script would be sent to the Linux machines, but in such a way that another type of L. would be interpreted.  You have a new shell, a custom-made shale, that interprets the MS-DOS commands and converts them into appropriate commands for Linux.  So you'd be running and interpreter and inside interpreter, so to speak.  The good part of this is blacks can accommodate many different types of shells.  Look around and you'll probably find a custom shale somebody has created that emulates the MS-DOS commands.
          I do really want to help you, I thought a little commentary might help you get out of the box.  And think of alternate solutions.
          One more I am.  If you're working in HTML, the conflict between Windows and UNIX no longer exists as to file name descriptions.  Both Windows and UNIX systems have to agree on file names inside the HTML context.  What that means is inside the browser with file-names have the forward symbol instead of the backward symbol.  So that would suggest the idea of using JavaScript inside the HTML page. Stop voice recognition

          NOTE: JavaScript is part of the browser and nada in common with Java.
          Except the name.

          Squashman



            Specialist
          • Thanked: 134
          • Experience: Experienced
          • OS: Other
          Re: Savin batch file results
          « Reply #16 on: March 21, 2012, 12:42:30 PM »
          I believe i found a solution that works, as windows does not like to save files with the ":", "/" or any other punctuarion

          Code: [Select]
          info.bat>%time:~0,2%-%time:~3,2%_%date:~10%-%date:~4,2%-%date:~7,2%.txt
          How is this for the code?? does anyone find an error?? This saves the results with a timestamp, but i am unable to save multiple files.
          Either append to the file or use the Computer Name variable as part as the output file name.

          To get the IP address you could do this.
          Code: [Select]
          :: Note: the following code will extract only the last IP address from the list
          FOR /F "TOKENS=2* DELIMS=:" %%A IN ('IPCONFIG /ALL ^| FIND "IP Address"') DO FOR %%B IN (%%A) DO SET IPADDR=%%B

          zeroburn

            Topic Starter


            Hopeful

          • Knowlege will take you further than any guide
          • Thanked: 2
            • Yes
            • Jared Kat Enterprises
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 7
          Re: Savin batch file results
          « Reply #17 on: March 27, 2012, 09:41:40 PM »
          Thanks geek, and i am going into some more advanced programming, right now that is over microsoft visual basic applications, but soon i will be trying for Java.

          I will post appropriate questions for java when i actually get into it in the appropriate topic.
          I consider myself a hacker. Not in the way of "I can break into your facebook" but in the way, I like to learn as much as I can, about anything i can. I don't just like having things fixed, I like to understand why it was broken and why a particular solution fixed it. It is just how I am, and how I will always be. As teachers have said before, you cant learn if you don't figure it out in your own mind.