Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3983930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:42:29+00:00 2026-05-20T05:42:29+00:00

I am trying to write a batch file to iteratively execute a fortran compiled

  • 0

I am trying to write a batch file to iteratively execute a fortran compiled executable. Normally one would go to the windows command prompt, type ‘Model.exe’. This would bring up a dos command window asking the user to type a required file name directly in to the command window at the dos prompt.

I want to write a batch file that will do this bit for me, and also iterate this step so that I can run 10 simulations consecutively instead of having to do it by hand. This kind of shell operation would be straightforward in linux, but I do not have this available.

My pseudo code would look like this:

for /L %%run in (1,1,10) do
(set str=Sim%%run
echo.%str% > input.txt
Model.exe < input.txt)

You could break this down in to the following steps:

  1. Assign variable ‘run’ a value. (e.g. 1)
  2. Concatenate this with a string (“Sim”) to make a new variable, “Sim1”
  3. echo this to a text file (“input.txt”)
  4. Read the variable “Sim1” from file “input.txt”
  5. Executable goes away and does its thing.
  6. Repeat steps 1 -> 5, but with a new variable calle “Sim2” etc.

I can get the above to work if I use set str=Sim1 and then echo this directly to “input.txt”, but I cannot get this to work as a loop. Am I missing something?

Best regards,

Ben

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:42:30+00:00Added an answer on May 20, 2026 at 5:42 am

    Ugh, cmd.exe’s treatment of variable expansion is ugly. So, you need “delayed expansion”, as follows:

    setlocal enabledelayedexpansion
    for /L %%i in (1,1,10) do (
    set str=Sim%%i
    echo !str! > input.txt
    Model.exe < input.txt)
    endlocal
    

    (Of course in this particular case you could just say echo Sim%%i > input.txt but I assume there’s a good reason why you want to go via another variable.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a windows batch file that can delete files from subdirectories.
I'm trying to write a batch file that takes the drive letter the batch
I'm trying to write a batch file in which I need the HEAD revision
I am trying to write a batch file that exists in an arbitrary directory
I am trying to write a small batch file for a task I do
I'm trying to write some PHP to upload a file to a folder on
I am trying to write a batch script and trying to wait 10 seconds
I am trying to write a batch(for win) and a shell script for linux
I'm trying to write two batch files that will allow me to switch the
I am a mercurial user on windows and I am trying to write a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.