Loading ...
Sorry, an error occurred while loading the content.

RE: [BATCH WORLD] Need help with batch file

Expand Messages
  • Marc Peterson
    Maybe try, e.g.,: for /f delims= %%a in ( dir /s /b /a:d ^| findstr /e .if9 ) do ( echo %%a cd %%a %%~na.exe -startup:alone
    Message 1 of 33 , Nov 1, 2012
    • 0 Attachment
      Maybe try, e.g.,:

      for /f "delims=" %%a in ('dir /s /b /a:d ^| findstr /e .if9') do (
      echo %%a
      cd "%%a"
      %%~na.exe -startup:alone < run_control.txt
      echo PSCAD successfully executed in "%%a\.." >> "%outfile%"
      )




      -----Original Message-----
      From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
      Behalf Of goshainganj
      Sent: Thursday, November 01, 2012 11:08 AM
      To: batchworld@yahoogroups.com
      Subject: [BATCH WORLD] Need help with batch file

      I have a batch file works pretty fine except one problem.

      The .exe filename i.e. XXXXX.exe is always contained in directory XXXXX.if9.

      Command ( dir /b /s /a:d | find ".if9" > mydir.txt ) lets me find the
      directory name. A typical output will be as follows:

      C:\Users\johnd\Documents\f2fver4.if9

      XXXXX in this case is f2fver4.

      How do I extract this information i.e. XXXXX from the list of directories
      and put them in command in FOR loop.


      ------------------------------------------------------
      @echo off
      if exist mydir.txt (del mydir.txt)
      if exist report.log (del report.log)
      dir /b /s /a:d | find ".if9" > mydir.txt
      setlocal
      set outfile=%cd%\report.log
      pushd .
      for /F "delims==" %%a in (mydir.txt) do (
      echo "%%a"
      cd "%%a"
      XXXXX.exe -startup:alone < run_control.txt
      echo PSCAD successfully executed in "%%a\.." >> "%outfile%"
      )
      popd
      del mydir.txt
      ------------------------------------------------------

      Thanx
      Kailash
    • Marc Peterson
      ... Capture the hour, use if logic to check the hour against your time window, use start to launch with high priority. So putting it together, maybe something
      Message 33 of 33 , Jan 15, 2013
      • 0 Attachment
        >> 1) From 18:00 PM to 06:00 AM use all CPU resources and run the %%~na.exe
        >> with highest priority and speed.

        Capture the hour, use if logic to check the hour against your time window,
        use start to launch with high priority. So putting it together, maybe
        something like this (untested):

        for /f "delims=" %%a in ('dir /s /b /a:d ^| findstr /e .if9') do (
        for /f "delims=:" %%h in ("%time%") do (
        echo %%a
        cd "%%a"
        if /i %%h leq 6 start /high %%~na.exe -startup:alone < run_control.txt
        if /I %%h geq 18 start /high %%~na.exe -startup:alone < run_control.txt
        echo PSCAD successfully executed in "%%a\.." >> "%outfile%"
        cd ..
        )
        )

        Though it would certainly make more sense to check the time first.

        --Marc


        > -----Original Message-----
        > From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
        > Behalf Of goshainganj
        > Sent: Tuesday, January 15, 2013 9:57 AM
        > To: batchworld@yahoogroups.com
        > Subject: Re: [BATCH WORLD] Need help with batch file
        >
        > Marc,
        >
        > The following advice turned out to be a boon for me. It works like a
        > charm.
        >
        > I wonder if it is possible to incorporate the following in this script:
        >
        > 1) From 18:00 PM to 06:00 AM use all CPU resources and run the %%~na.exe
        > with highest priority and speed.
        >
        > Regards and thanx
        > Kailash
        >
        >
        > --- In batchworld@yahoogroups.com, "Marc Peterson" wrote:
        > >
        > > The ~n modifier on %%a extracts the base part of the name, so if %%a is
        > > XXXXX.if9 then %%~na is XXXXX and %%~na.exe is XXXXX.exe. See the last
        > > section of "for /?" for more info.
        > >
        > > --Marc
        > >
        > > -----Original Message-----
        > > From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
        > > Behalf Of kn srivastava
        > > Sent: Monday, November 05, 2012 1:46 AM
        > > To: batchworld@yahoogroups.com
        > > Subject: Re: [BATCH WORLD] Need help with batch file
        > >
        > > On Thu, Nov 1, 2012 at 6:59 PM, Marc Peterson wrote:
        > >
        > > > Maybe try, e.g.,:
        > > >
        > > > for /f "delims=" %%a in ('dir /s /b /a:d ^| findstr /e .if9') do (
        > > > echo %%a
        > > > cd "%%a"
        > > > %%~na.exe -startup:alone < run_control.txt
        > > > echo PSCAD successfully executed in "%%a\.." >> "%outfile%"
        > > > )
      Your message has been successfully submitted and would be delivered to recipients shortly.