Announcement

Collapse
No announcement yet.

how to read variable names from user input within a batch script?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to read variable names from user input within a batch script?

    I would like to edit a batch command file so that the last parameter, is updated by the user, and, the batch file checks whether the file exists and is accessible before running the command:

    @ECHO OFF
    C:
    CD "\Documents and Settings\Jon\workspace\JavaDev\corejava7\v2\v2ch4\ ExecSQL"

    rem if <<Authors.sql>> exists run the next command
    java -cp postgresql-8.4-702.jdbc4.jar;. ExecSQL <<Authors.sql>>
    pause

  • #2
    Re: how to read variable names from user input within a batch script?

    Use

    Code:
    Set /p string=
    Where string is your variable. After the variable is set it is called using %string%

    Comment


    • #3
      Re: how to read variable names from user input within a batch script?

      Originally posted by jon80 View Post
      I would like to edit a batch command file so that the last parameter, is updated by the user, and, the batch file checks whether the file exists and is accessible before running the command:

      Code:
      @ECHO OFF
      C:
      CD "\Documents and Settings\Jon\workspace\JavaDev\corejava7\v2\v2ch4\ExecSQL"
      
      rem if <<Authors.sql>> exists run the next command
      java -cp  postgresql-8.4-702.jdbc4.jar;. ExecSQL <<Authors.sql>>
      pause
      Code:
      @echo off
      
      Set "ExecSqlDir=%userprofile%\workspace\JavaDev\corejava7\v2\v2ch4\ExecSQL"
      
      pushD "%ExecSqlDir%" ||goto :directorynotfound
      
      dir *.sql /b
      echo.
      
      Set /p "AuthorsSQL=Please enter what I want to know:  "
      
      if exist "%ExecSqlDir%\%AuthorsSQL%" (
      java -cp postgresql-8.4-702.jdbc4.jar;. ExecSQL "%ExecSqlDir%\%AuthorsSQL%"
      ) else (goto :filenotexist)
      
      popD
      
      echo.
      echo Done.
      
      pause
      goto :EOF ______________________________________________________________
      
      :directorynotfound
      echo.
      echo You not have access to this application:
      echo %ExecSqlDir%
      pause
      goto :EOF
      
      :filenotexist
      echo.
      echo what you entered was not found in the profile directory:
      echo %AuthorsSQL%
      pause
      goto :EOF

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment

      Working...
      X