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

Author Topic: make batch save %var% to .txt and retrieve %var% from .txt  (Read 8243 times)

0 Members and 1 Guest are viewing this topic.

Ädamas

    Topic Starter


    Beginner

    Thanked: 1
    i have this program that can run on the command line (goes faster that way) and i have a .bat that makes it easier to do this what i want is to save where it it up to when it exits using a .txt file so that it has an input file and
    makes an output file that becomes the new input file and it goes on and on and on(until i stop it)
    i would like to name the files 1(the 1st input),2,3,4,5,6,...

    p.s no files are deleted in the process and i would like to have it run and when i want to stop i can and when i start it again it can go from where it left off (that is why i want to save a variable to a .txt file

    p.s.s
    the program is evolve 4.0 and can be found here http://www.stauffercom.com/evolve4/
    some more info about the command line is here http://www.stauffercom.com/evolve4/evolve_batch.html

    [attachment deleted by admin]
    you're just jealous because the voices talk to me, and not you.

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: make batch save %var% to .txt and retrieve %var% from .txt
    « Reply #1 on: May 10, 2009, 09:49:36 AM »
    i have this program that can run on the command line (goes faster that way) and i have a .bat that makes it easier to do this what i want is to save where it it up to when it exits using a .txt file so that it has an input file and
    makes an output file that becomes the new input file and it goes on and on and on(until i stop it)
    i would like to name the files 1(the 1st input),2,3,4,5,6,...

    p.s no files are deleted in the process and i would like to have it run and when i want to stop i can and when i start it again it can go from where it left off (that is why i want to save a variable to a .txt file

    p.s.s
    the program is evolve 4.0 and can be found here http://www.stauffercom.com/evolve4/
    some more info about the command line is here http://www.stauffercom.com/evolve4/evolve_batch.html

    Ok...

    echo %var%>filename.txt
    rem The above line sends the contents of %var% to filename.txt
    set /p var=<filename.txt
    rem The above line recieves the contents of filename.txt and sets %var% as it.

    Understand?
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    Ädamas

      Topic Starter


      Beginner

      Thanked: 1
      Re: make batch save %var% to .txt and retrieve %var% from .txt
      « Reply #2 on: May 11, 2009, 01:28:40 AM »
      it is not writeing to the file but it is reading from it
      this is my batch
      Code: [Select]
      @echo off
      :setup0
      echo do you want to start from where you left off[y\n]
      set/p "cho=>"
      if %cho%==y goto setup1
      if %cho%==n goto setup2

      :setup1
      cls
      echo time
      set/p "time=>"
      echo input
      set /p in=<filename.txt
      echo %out%
      echo output
      set/p "out=>"
      echo are the time,input and output correct[y/n]
      set/p "cho=>"
      if %cho%==y goto evolve_b
      if %cho%==n goto setup
      %out%>filename.txt

      :setup2
      cls
      echo time
      set/p "time=>"
      echo input
      set/p "in=>"
      echo output
      set/p "out=>"
      echo are the time,input and output correct[y/n]
      set/p "cho=>"
      if %cho%==y goto evolve_b
      if %cho%==n goto setup

      :evolve_b
      cd C:\Program Files\Evolve
      evolve_batch
      evolve_batch s %time% %in%.evolve %out%.evolve

      %out% is the variable i want to save and i want to make %in% have the value of %out% when i start it again
      you're just jealous because the voices talk to me, and not you.

      gpl



        Apprentice
      • Thanked: 27
        Re: make batch save %var% to .txt and retrieve %var% from .txt
        « Reply #3 on: May 11, 2009, 02:06:25 AM »
        The easiest way to retrieve a value from a file is
        Set /P in=<filename.ext

        Note this will read only the first line of filename.ext and will put the value into %in%

        Graham

        Ädamas

          Topic Starter


          Beginner

          Thanked: 1
          Re: make batch save %var% to .txt and retrieve %var% from .txt
          « Reply #4 on: May 11, 2009, 04:52:14 AM »
          it now reads from the file and saves to the file but not with the value of %out% instead it deletes all the text in the .txt
          you're just jealous because the voices talk to me, and not you.

          Reno



            Hopeful
          • Thanked: 32
            Re: make batch save %var% to .txt and retrieve %var% from .txt
            « Reply #5 on: May 11, 2009, 08:33:50 AM »
            Code: [Select]
            @echo off & setlocal
            :setup0
            if not exist save.txt goto setup2
            echo do you want to start from where you left off[y\n]
            set/p "cho=>"
            if %cho%==y goto setup1
            if %cho%==n goto setup2
            goto:eof

            :setup1
            for /f "tokens=*" %%a in (save.txt) do %%a
            set out
            goto:eof

            :setup2
            set/p out=enter string:
            echo variable out=%out% will be saved as save.txt
            >save.txt echo set out=%out%

            sample untested code

            Ädamas

              Topic Starter


              Beginner

              Thanked: 1
              Re: make batch save %var% to .txt and retrieve %var% from .txt
              « Reply #6 on: May 12, 2009, 12:17:04 AM »
              @ Reno

              where do you put the code in the batch every time i answer yes to the "do you want to start from where you left off[y\n]"
              it exits the batch
              Code: [Select]
              @echo off & setlocal
              :setup0
              if not exist save.txt goto setup3
              echo do you want to start from where you left off[y\n]
              set/p "cho=>"
              if %cho%==y goto setup1
              if %cho%==n goto setup2
              goto:eof

              :setup1
              cls
              for /f "tokens=*" %out% in (save.txt) do %out%
              echo time
              set/p "time=>"
              echo input
              echo %out%
              echo %out%
              echo output
              set/p "out=>"
              echo are the time,input and output correct[y/n]
              set/p "cho=>"
              if %cho%==y goto evolve_b
              if %cho%==n goto setup

              :setup2
              cls
              echo time
              set/p "time=>"
              echo input
              set/p "in=>"
              echo output
              set/p "out=>"
              echo are the time,input and output correct[y/n]
              set/p "cho=>"
              if %cho%==y goto evolve_b
              if %cho%==n goto setup

              :setup3
              set/p out=enter string:
              echo variable out=%out% will be saved as save.txt
              >save.txt echo set out=%out%

              :evolve_b
              cd C:\Program Files\Evolve
              evolve_batch
              evolve_batch s %time% %out%.evolve %out%.evolve

              i changed it a bit it would not fit



              you're just jealous because the voices talk to me, and not you.

              Reno



                Hopeful
              • Thanked: 32
                Re: make batch save %var% to .txt and retrieve %var% from .txt
                « Reply #7 on: May 12, 2009, 01:13:29 AM »
                 ::) ::) ::) i got headache
                i only give example how to save a bunch of variables into a txt file and later retrieve the vars the next time batch is executed.

                for /f "tokens=*" %out% in (save.txt) do %out%    <--- incorrect for loop syntax
                :setup1  <--- let's say this is sort of a "batch function" in OOP term, you have to put goto:eof at the end of each function except the last one, or the the next line of code will be executed


                Code: [Select]
                :evolve_b
                cd C:\Program Files\Evolve
                evolve_batch
                evolve_batch s %time% %out%.evolve %out%.evolve
                what are the value of var time,out,evolve,out on the following 2 condition:
                1.do you want to start from where you left off[y\n]  Y
                2.do you want to start from where you left off[y\n]  N

                it would be nice if you can gives example as i don't quite understand the problem.

                Ädamas

                  Topic Starter


                  Beginner

                  Thanked: 1
                  Re: make batch save %var% to .txt and retrieve %var% from .txt
                  « Reply #8 on: May 12, 2009, 01:39:10 AM »
                  Quote
                  what are the value of var time,out,evolve,out on the following 2 condition:
                  1.do you want to start from where you left off[y\n]  Y
                  2.do you want to start from where you left off[y\n]  N
                  1) time is hours(h),minutes(m),seconds(s) or steps(u)
                        so when i type in the time it is
                  45s(seconds)
                  30m(minutes)
                  24h(hours)
                  4000u(steps)

                  in is the starting conditions of the simulation (in this case it is the previous out file)

                  .evolve is not a variable it is just the files extension

                  out is the output file


                  2)in this case i set the varables to anything i want to.
                  you're just jealous because the voices talk to me, and not you.

                  Reno



                    Hopeful
                  • Thanked: 32
                    Re: make batch save %var% to .txt and retrieve %var% from .txt
                    « Reply #9 on: May 12, 2009, 03:30:28 AM »
                    hmm, maybe something like below works??

                    Code: [Select]
                    @echo off & setlocal

                    :setup
                    set/p c=do you want to start from where you left off [y\n] :
                    echo.%c%|findstr/ix "y n yes no">nul || goto:setup

                    if /i %c:~,1%.==y. for /f "tokens=*" %%a in (save.txt) do set %%a
                    if /i %c:~,1%.==n. (
                    set/p var_time=time :
                    set/p var_in=input :
                    set/p var_out=output :
                    set var_>save.txt
                    )

                    :validateYesNo
                    echo evolve_batch s %var_time% %var_in%.evolve %var_out%.evolve
                    set/p c=are the time,input and output correct [y/n] :
                    echo.%c%|findstr/ix "y n yes no">nul || goto:validateYesNo

                    if /i %c:~,1%.==n. goto:setup
                    cd C:\Program Files\Evolve
                    evolve_batch
                    evolve_batch s %var_time% %var_in%.evolve %var_out%.evolve

                    Ädamas

                      Topic Starter


                      Beginner

                      Thanked: 1
                      Re: make batch save %var% to .txt and retrieve %var% from .txt
                      « Reply #10 on: May 13, 2009, 01:15:23 AM »
                      wow Reno
                      that one looked very good but i wanted it to set %var_in% to what %var_out% was last time
                      you're just jealous because the voices talk to me, and not you.

                      Reno



                        Hopeful
                      • Thanked: 32
                        Re: make batch save %var% to .txt and retrieve %var% from .txt
                        « Reply #11 on: May 13, 2009, 03:34:28 AM »
                        Code: [Select]
                        @echo off & setlocal & set c=n

                        if not exist save.txt goto skip
                        :setup
                        set c=&set/p c=do you want to start from where you left off [y\n] :
                        echo.%c%|findstr/ix "y n yes no">nul || goto:setup

                        :skip
                        if /i %c:~,1%.==y. for /f "tokens=*" %%a in (save.txt) do set %%a
                        if /i %c:~,1%.==n. (
                        set/p var_time=time :
                        set/p var_in=input :
                        )
                        set/p var_out=output :

                        :validateYesNo
                        echo evolve_batch s %var_time% %var_in%.evolve %var_out%.evolve
                        set c=&set/p c=are the time,input and output correct [y/n] :
                        echo.%c%|findstr/ix "y n yes no">nul || goto:validateYesNo

                        if /i %c:~,1%.==n. goto:setup
                         >save.txt echo var_time=%var_time%
                        >>save.txt echo var_in=%var_out%
                        cd C:\Program Files\Evolve
                        evolve_batch
                        evolve_batch s %var_time% %var_in%.evolve %var_out%.evolve

                        CODE UPDATED. CHECK POST #11
                        « Last Edit: May 13, 2009, 04:37:55 AM by Reno »

                        Ädamas

                          Topic Starter


                          Beginner

                          Thanked: 1
                          Re: make batch save %var% to .txt and retrieve %var% from .txt
                          « Reply #12 on: May 13, 2009, 04:17:58 AM »
                          i wanted it to set %var_in% to what %var_out% was last time it was ran so

                          //first run
                          %var_in%=1
                          %var_out%=2
                          //second run
                          %var_in%=2(from save.txt{so i don't need to enter this})
                          %var_out%=3
                          //third run
                          %var_in%=3(again from save.txt)
                          %var_out%=4

                          and so on

                          you're just jealous because the voices talk to me, and not you.

                          Ädamas

                            Topic Starter


                            Beginner

                            Thanked: 1
                            Re: make batch save %var% to .txt and retrieve %var% from .txt
                            « Reply #13 on: May 13, 2009, 05:10:11 AM »
                            perfect  ;D thank you so much
                            you're just jealous because the voices talk to me, and not you.