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

Author Topic: Commands will run in dos window, but not in bat file  (Read 5668 times)

0 Members and 1 Guest are viewing this topic.

ErikG

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Unknown
    Commands will run in dos window, but not in bat file
    « on: January 27, 2012, 02:00:04 PM »
    I'm trying to execute a dos batch file with the following commands:

    C:\hysplit4\exec\hyts_std
    C:\hysplit4\exec\trajplot -iof12jun0923 -ojun12plot -v1 -l12 -m3 -a5
    c:\hysplit4\exec\ascii2shp -d jun12plot lines < GIS_traj_ps_01.txt

    The first line executes a meteorological model that develops a back trajectory or path of an air parcel.  It looks for an input file named CONTROL and uses its information to execute.  If it can't find the input file it defaults to asking for input via keyboard.

    The second line takes the output file of the met model and creates a postscript graphic file of the trajectory and creates two additional output files (one of them GIS_traj_ps_01.txt) for conversion to an ESRI GIS shapefile.

    The third line takes the file GIS_traj_ps_01.txt and converts the data into an ArcGIS shape file which can be imported into ArcGIS.  This system comes with a GUI which can handle one trajectory at a time, but to do an adequate analysis, I need to do several hundred.  Ideally, I would like to automate this process and loop through the process.  I have tried using Excel VBA's shell function for these and got nowhere.  The hyts_std executable could not find the CONTROL file and defaults to asking for keyboard input.

    I can get all three commands to work properly when entered manually into a DOS window from the keyboard.  They can find the necessary input files and execute properly.  When I put them into a single bat file, however, they don't work.  I use the latest version of Windows XP at work and Windows Home Premium at home.  Any suggestions?  Many thanks in advance!

    ErikG

    Salmon Trout

    • Guest
    Re: Commands will run in dos window, but not in bat file
    « Reply #1 on: January 27, 2012, 02:09:53 PM »
    When I put them into a single bat file, however, they don't work.

    Don't work? How? (In what way don't they work? With what symptoms/messages etc?)

    ErikG

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Unknown
      Re: Commands will run in dos window, but not in bat file
      « Reply #2 on: January 27, 2012, 02:49:47 PM »
      I've only put them in batch files with the hyts_std executable by itself in one file and the trajplot and ascii2shp in the other batch file.

      The hyts_std returns the default request for keyboard input.
      The other two executables simply flash a dos window open and shut (to quickly to see anything written)

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: Commands will run in dos window, but not in bat file
      « Reply #3 on: January 27, 2012, 09:20:50 PM »
      Launch the batch file from the command prompt or put a pause in the script.

      You need to be a little more clear on what you are doing. You need to show us the code that is in the batch file and its output.

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Commands will run in dos window, but not in bat file
      « Reply #4 on: January 27, 2012, 11:25:29 PM »
      Timing may be an issue. An new task can start before the output file is closed from an earlier task.  If so, there needs to be something that makes sure the file is ready for the next task.
      You may wish to use a pipe.

      jimschel



        Greenhorn

        • Experience: Beginner
        • OS: Unknown
        Re: Commands will run in dos window, but not in bat file
        « Reply #5 on: February 14, 2012, 03:51:59 PM »
        I suggest you put a pause statement after each command. When the program pauses, open another DOS command and check to see if the files you need have actually been created. Also there is a 'DELAY.COM' command I picked up someplace years ago. Probably Norton Utilities. It will wait for x number of seconds. I us it a lot of times to wait for 2-5 seconds so files will have different time stamps. Maybe the time that is showed, but also the 1/10 of seconds. This way I can enter 'DIR /OD' and I an see exactly the order the fils were created. Hope this helped



        ErikG

          Topic Starter


          Starter

          • Experience: Beginner
          • OS: Unknown
          Re: Commands will run in dos window, but not in bat file
          « Reply #6 on: February 14, 2012, 04:11:31 PM »
          Thanks very much for all the help!  I've got things working now.

          Squashman



            Specialist
          • Thanked: 134
          • Experience: Experienced
          • OS: Other
          Re: Commands will run in dos window, but not in bat file
          « Reply #7 on: February 14, 2012, 08:53:24 PM »
          Thanks very much for all the help!  I've got things working now.
          Would help all that find this thread later on if you would post your final solution.

          ErikG

            Topic Starter


            Starter

            • Experience: Beginner
            • OS: Unknown
            Re: Commands will run in dos window, but not in bat file
            « Reply #8 on: March 08, 2012, 06:18:50 PM »
            I needed to make sure that I was in the correct directory when running the file so I added: cd c:\hysplit4\exec to the top of the three commands.