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

Author Topic: Writing command line outputs to local files  (Read 6227 times)

0 Members and 1 Guest are viewing this topic.

ajetrumpet

    Topic Starter


    Rookie

    Writing command line outputs to local files
    « on: October 31, 2009, 10:55:32 PM »
    hello all,

    I am following this thread here but do not understand it: http://www.computerhope.com/forum/index.php/topic,94281.0.html

    I am generally looking for a command that will automatically write the result of a command that I give to DOS out to a text file that I have stored on my local computer.  Is there such a command?  I have tried many MANY combinations of the redirect but it is blank in the text file after it says the transfer is complete.  I am running windows VISTA and this is what I've tried that yields a complete message:
    Code: [Select]
    dir > dirs.txtI am in the correct local directory, but I think there is a fundemental thing I am missing because I can type in any local file name even if it doesn't exist and it will tell me that the transfer is completed.  can anybody help me out here?  I'm not an expert in DOS but I know my way around.  thanks!

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Writing command line outputs to local files
    « Reply #1 on: October 31, 2009, 11:09:42 PM »
    Did you try this?

    Quote
    DIR *.* /b > Dir.txt
    TYPE Dir.txt

    ajetrumpet

      Topic Starter


      Rookie

      Re: Writing command line outputs to local files
      « Reply #2 on: October 31, 2009, 11:16:41 PM »
      is that all supposed to be one line?  when I type the first line into the prompt, I get this:
      Code: [Select]
      Usage: dir remote directory local filethat's all I can get to work right now.  not sure how to use the TYPE command you are referring to.  I know what it does, but not sure about the context.  can you elaborate just a tad?

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Writing command line outputs to local files
      « Reply #3 on: October 31, 2009, 11:45:41 PM »
      It was two lines. The DIR output goes into a new file named 'Dir.TXT' and
      The second line is where  we see the contents of that file.

      That response you get is unknown to me. I pleas ignorance.
      That response indicates that you have started the FTP command.
      You said:
      Quote
      ...the transfer is completed.

      Now it starts to make sense. Look at this:
      Code: [Select]

      Microsoft Windows [Version 6.0.6001]
      Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

      C:\Users\Kohn>FTP
      ftp> help
      Commands may be abbreviated.  Commands are:

      !               delete          literal         prompt          send
      ?               debug           ls              put             status
      append          dir             mdelete         pwd             trace
      ascii           disconnect      mdir            quit            type
      bell            get             mget            quote           user
      binary          glob            mkdir           recv            verbose
      bye             hash            mls             remotehelp
      cd              help            mput            rename
      close           lcd             open            rmdir
      ftp> quit

      C:\Users\Kohn>

      You need to 'quit' FTP before you do DOS commands.


      ajetrumpet

        Topic Starter


        Rookie

        Re: Writing command line outputs to local files
        « Reply #4 on: October 31, 2009, 11:50:12 PM »
        Now I am getting the picture.  The writing to a text file works with the normal LOCAL DOS prompt, but what I want is for it to work while in FTP mode.  Is that not possible?

        Geek,

        I just tried this in FTP mode:
        Code: [Select]
        ls > dir.txtit created a dir.txt file but didn't put anything in it again!  I also tried this:
        Code: [Select]
        ls /b > dir.txtbut got the same USAGE message as before.  any other hints?  I'm at a loss.  thanks for all your help so far.
        « Last Edit: November 01, 2009, 12:12:09 AM by ajetrumpet »

        gh0std0g74



          Apprentice

          Thanked: 37
          Re: Writing command line outputs to local files
          « Reply #5 on: November 01, 2009, 12:23:28 AM »
          In FTP mode??
          Code: [Select]
          c:\test> ftp -s yourftp    > out.txt
          NB: check the syntax for ftp usage.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: Writing command line outputs to local files
          « Reply #6 on: November 01, 2009, 12:25:22 AM »
          OK.
          The /B is not for the FTP program.

          This first time you do it say:
          ls > dir.txt
          And the second time use:
          ls >> dir.txt

          Hope that helps. I have to q jut for tonight.
          When do I set the clock back?

          ajetrumpet

            Topic Starter


            Rookie

            Re: Writing command line outputs to local files
            « Reply #7 on: November 01, 2009, 12:26:56 AM »
            You set it back at 2am.  Thanks for the help all.  if I can't get it to work, I'll be back!

            gh0std0g74



              Apprentice

              Thanked: 37
              Re: Writing command line outputs to local files
              « Reply #8 on: November 01, 2009, 12:56:41 AM »
              i don't have a Windows computer right now so can't test my theory, but don't think you can do redirection INSIDE of a FTP session. Do it outside on the command line like what i posted. Anyway, test it out and see.

              ajetrumpet

                Topic Starter


                Rookie

                Re: Writing command line outputs to local files
                « Reply #9 on: November 01, 2009, 01:29:24 AM »
                In FTP mode??
                Code: [Select]
                c:\test> ftp -s yourftp    > out.txt
                NB: check the syntax for ftp usage.
                gh,

                can you please explain the "yourftp" line?  can you tell me what each part of that code is supposed to do?  if I type:
                Code: [Select]
                ftp -sI get a list of "-" switches and explanations.  the "-s:filename" part of the explanatory section says "specifiies a txt file for FTP commands.  the commands will be run automatically after FTP starts.

                is that what you were trying to tell me?

                Geek-9pm


                  Mastermind
                • Geek After Dark
                • Thanked: 1026
                  • Gekk9pm bnlog
                • Certifications: List
                • Computer: Specs
                • Experience: Expert
                • OS: Windows 10
                Re: Writing command line outputs to local files
                « Reply #10 on: November 01, 2009, 08:42:32 AM »
                Quote
                How to create a Windows FTP script

                Create a text document with commands used when in FTP.  Below is an example of what such a script may look like:

                open ftp.domain.com
                username
                password
                cd public_html
                dir
                get file.txt
                bye


                The above script will log into the ftp site ftp.domain.com. Once connected, it will enter the username and then the password (substitute username for your username and password for your password). Once logged in, the script then goes into the public_html directory, gets a directory listing and then uses the get command to get the file called file.txt. Once the file is received, it logs off using the bye command.

                Once the script file has been created, for example, if it was called script.txt, to execute this script with ftp you would type:

                ftp -s:script.txt


                http://www.computerhope.com/software/ftp.htm#support

                ajetrumpet

                  Topic Starter


                  Rookie

                  Re: Writing command line outputs to local files
                  « Reply #11 on: November 01, 2009, 10:50:54 AM »
                  geek,

                  I have since been able to do what I need.  and I've already known how to do what you just posted.  I think I'm almost there and I'm greatful for all of your help that you have given to me.  I am doing this in a MS program using VBA, which is what that script is for.  If you don't mind, can I ask you one more question?  Everytime I read my text file with my procedure, it is not registering the change that I just made to it, that being the new contents I just wrote to it with the funciton I am in.  Do you know if there is a way that I can refresh a file list in windows explorer within a VBA procedure? (I know this is a dos forum)

                  Geek-9pm


                    Mastermind
                  • Geek After Dark
                  • Thanked: 1026
                    • Gekk9pm bnlog
                  • Certifications: List
                  • Computer: Specs
                  • Experience: Expert
                  • OS: Windows 10
                  Re: Writing command line outputs to local files
                  « Reply #12 on: November 01, 2009, 11:18:01 AM »
                  Simple answer is NO.
                  A common problem in some MS programs. You have to restart the program to make it refresh its copy of files and directories. As far as I know, you have to exit VB and reload.

                  ajetrumpet

                    Topic Starter


                    Rookie

                    Re: Writing command line outputs to local files
                    « Reply #13 on: November 01, 2009, 11:29:52 AM »
                    you don't have to exit VB and reload, as running 2 procedures yields a refresh.  how about this one for you geek?

                    if you don't mind I have another question for you (last one!)...

                    I am capturing everything just perfectly, but there is a problem I can't get my head around.  I have this code for example:
                    Code: [Select]
                          Dim vPath As String
                          Dim vFTPServ As String
                          Dim fNum As Long
                         
                          vPath = "C:"
                          vFTPServ = "www.domain.com"
                          fNum = FreeFile()
                         
                          Open vPath & "\FtpComm.txt" For Output As #fNum
                          Print #1, "USER myUN" ' your login
                          Print #1, "pass" ' your password
                          Print #1, "dir " & Me.namefield & " c:\test.txt"
                          Print #1, "close"
                          Print #1, "quit"
                          Close
                         
                          Shell "ftp -n -i -g -s:" & vPath & "\FtpComm.txt " & vFTPServ, vbHide
                    i am doing this everytime I want to view the contents of the TEST text file.  my question is, is there a way that I can leave the FTP session open, and keep printing lines in the FTPCOMM file and keep executing DOS commands one at a time this way instead of opening and closing the connection each time?  thanks!

                    Geek-9pm


                      Mastermind
                    • Geek After Dark
                    • Thanked: 1026
                      • Gekk9pm bnlog
                    • Certifications: List
                    • Computer: Specs
                    • Experience: Expert
                    • OS: Windows 10
                    Re: Writing command line outputs to local files
                    « Reply #14 on: November 01, 2009, 11:50:26 AM »
                    We are at the point where we need to close this thread and start an new one in programming. When you do, be sure to identify which version of VB and which OS you are using. It does make a difference.
                    My gut feeling is that you have to use the FTP client library and not the FTP program itself.  It is meant to be a stand-alone program.

                    The member that can best help you on this is BC_Programmer.
                    So start a new thread in Programming ans describe the problem as a VB thing and get his attention.