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

Author Topic: Auto respond to command line prompts in a batch file?  (Read 28061 times)

0 Members and 1 Guest are viewing this topic.

HarryBatt

    Topic Starter


    Starter

    Auto respond to command line prompts in a batch file?
    « on: July 26, 2010, 06:54:26 AM »
    I am a reasonably experienced VBA developer and have recently started to integrate DOS scripts into my code. I have very little knolwdge of batch file scripting and wondered if there is any way of auto responding to command line prompts?

    I have used telnet to send emails but as this requires user input I cannot automate this into a script abd call the shell function in VB.

    The code sequence I use is:

    telnet
    o anydomain.co.uk 587
    ehlo
    auth login
    Z2VycnloZWxtZUBaaaaataWRhc2VkdWNhdGlvbi 5jby51aw== '64 bit username
    NHNjb3JcxxxxswaWFfffuMg==              '64 bit password
    mail from:[email protected]
    rcpt to:[email protected]
    data
    Message
    echo.
    quit



    marylane



      Rookie

    • USA
    • Thanked: 1
      Re: Auto respond to command line prompts in a batch file?
      « Reply #1 on: July 26, 2010, 03:22:05 PM »
      Try command line arguments.


      or

      echo Y |  your batch
      USA

      Salmon Trout

      • Guest
      Re: Auto respond to command line prompts in a batch file?
      « Reply #2 on: July 26, 2010, 03:29:41 PM »
      Wow that's real helpful, Marybill.  ::)

      marylane



        Rookie

      • USA
      • Thanked: 1
        Re: Auto respond to command line prompts in a batch file?
        « Reply #3 on: July 26, 2010, 03:56:35 PM »
        HarryBatt,

        I see you have received several suggestions from the experts here at ComputerHope.

        Good Luck

        Many of the suggestions are from the UK.
        « Last Edit: July 26, 2010, 04:08:31 PM by marylane »
        USA

        HarryBatt

          Topic Starter


          Starter

          Re: Auto respond to command line prompts in a batch file?
          « Reply #4 on: July 26, 2010, 05:16:11 PM »
          Commant line arguments sound like they will do the job... Just need to find out how to code them.... :o

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: Auto respond to command line prompts in a batch file?
          « Reply #5 on: July 26, 2010, 05:31:44 PM »
          you can use a file for input by using redirection, I believe.

          something like

          Code: [Select]
          telnet < ftpcommands.txt

          in your case "ftpcommands.txt" or whatever you chose to name the file will need to contain the "code sequence" you gave, sans the "telnet" line at the top.

          I was trying to dereference Null Pointers before it was cool.

          marylane



            Rookie

          • USA
          • Thanked: 1
            Re: Auto respond to command line prompts in a batch file?
            « Reply #6 on: July 26, 2010, 06:44:32 PM »
            Command line arguments sound like they will do the job... Just need to find out how to code them.... :o

            Code: [Select]
            @echo off

            echo sleep.exe  %1
            sleep.exe  %1

            Output:

            C:\>blog.bat   5

            echo sleep.exe  5
            sleep.exe  5
            USA

            marylane



              Rookie

            • USA
            • Thanked: 1
              Re: Auto respond to command line prompts in a batch file?
              « Reply #7 on: July 26, 2010, 08:12:45 PM »
              Command line arguments sound like they will do the job... Just need to find out how to code them.... :o

               has it right, %* for everything. You might also find these useful:

              %0 - the name of the batch file itself
              %1 is the first command line parameter,
              %2 is the second command line parameter,
              and so on till %9 (and SHIFT can be used for those after the 9th).

              %~dpnx0 - is the fully qualified path name of the script (d:\scripts\some-batch.bat)
              %~dp0 - drive and path to the script (d:\scripts)

              More info examples at http://www.ss64.com/nt/syntax-args.html and http://www.robvanderwoude.com/parameters.html

               
              USA

              HarryBatt

                Topic Starter


                Starter

                Re: Auto respond to command line prompts in a batch file?
                « Reply #8 on: July 28, 2010, 02:05:23 AM »
                Thanks all. I am just back from London having suffered torture by paperwork for my sons F1 visa in the US embassy. I will try to implement the suggestions today. Hopefully it will accept the text script anf fully qualified UNC path . Will report back. Thanks again