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

Author Topic: Equivalent of Unix eval in Windows  (Read 21433 times)

0 Members and 1 Guest are viewing this topic.

preeth

    Topic Starter


    Greenhorn

    Equivalent of Unix eval in Windows
    « on: December 14, 2009, 03:08:15 AM »
    Hi,

    I want to convert the following unix command line to windows command line:
    eval `sb-config --env`

    "sb-config --env" returns the commands to set some environment variables. The result is having multiples lines of SET commands.

    So how can I execute the sb-config result in a windows batch script?

    The only solution I could come up with is:
    sb-config --env > sbenv.cmd
    call sbenv.cmd
    del sbenv.cmd

    If anybody has any better suggestions plz let me know.

    Thnx n Regards,
    Preeth

    uhoraho

    • Guest
    Re: Equivalent of Unix eval in Windows
    « Reply #1 on: December 14, 2009, 09:17:13 AM »
    You can use the following:

    del set.cmd & FOR /F %V in ('set') do echo SET %V >> set.cmd

    preeth

      Topic Starter


      Greenhorn

      Re: Equivalent of Unix eval in Windows
      « Reply #2 on: December 14, 2009, 10:29:29 PM »
      Hi uhoraho,

      Thanks for ur reply. I am a newbie to windows scripting. So can u please explain wht this line does?

      Regards,
      Preeth

      Salmon Trout

      • Guest
      Re: Equivalent of Unix eval in Windows
      « Reply #3 on: December 15, 2009, 12:21:02 AM »
      if you...

      1. type SET or set at the prompt

      2. run the code changing it slightly like this

      del myset.cmd & FOR /F %V in ('set') do echo SET %V >> myset.cmd

      (It is bad practice to have a command script with the same name as a built in command)

      3. examine the contents of the new file myset.cmd (which is a script)

      ... you will see for yourself what it does - namely that FOR /F captures the output of the command 'set', line by line, into the loop metavariable %V, and the >> operator echoes these lines, (with the word SET and a space prepended), in append mode, to the named file myset.cmd.

      Type FOR /? and SET /? at the prompt for more help.


      preeth

        Topic Starter


        Greenhorn

        Re: Equivalent of Unix eval in Windows
        « Reply #4 on: December 15, 2009, 12:34:03 AM »
        Hi,

        Thanx again...

        What I wanted was execute the output of the command line "sb-config --env"

        So where should I put this command in the following line:
        del myset.cmd & FOR /F %V in ('set') do echo SET %V >> myset.cmd

        Regards,
        Preeth

        Salmon Trout

        • Guest
        Re: Equivalent of Unix eval in Windows
        « Reply #5 on: December 15, 2009, 12:37:12 AM »
        Thanx again...

        What I wanted was execute the output of the command line "sb-config --env"

        So where should I put this command in the following line:
        del myset.cmd & FOR /F %V in ('set') do echo SET %V >> myset.cmd


        Have you typed FOR /? and read the help?

        preeth

          Topic Starter


          Greenhorn

          Re: Equivalent of Unix eval in Windows
          « Reply #6 on: December 15, 2009, 05:59:37 AM »
          Yes I read the FOR help.

          But I think you didnt get the real requirement.

          When I did
          del myset.cmd & FOR /F %i in ('sb-config --env') do echo SET %i >> myset.cmd
          It was printing 2 lines of "SET set" into the myset.cmd file.

          But this one:
          del myset.cmd & FOR /F "tokens=1,2" %i in ('sb-config --env') do echo SET %i %j >> myset.cmd
          It was printing the command output with a SET prepended to each line.

          But I dont want to prefix anything to the output of the command. The command "sb-config --env" output following lines:
          set STREAMBASE_HOME="D:\StreamBase\StreamBase.6.3"
          set PATH="D:\StreamBase\StreamBase.6.3\bin";%PATH%
          I just want to execute them.

          I already know that I can do
          sb-config --env > sbenv.cmd
          call sbenv.cmd
          del sbenv.cmd

          Is there any better ways of doing this. ie. without creating an temp cmd file.

          Thanks and Regards,
          Preeth


          gpl



            Apprentice
          • Thanked: 27
            Re: Equivalent of Unix eval in Windows
            « Reply #7 on: December 15, 2009, 06:26:16 AM »
            I dont think it was appreciated that SET appeared in the output

            Try this
            FOR /F "tokens=1,2" %i in ('sb-config --env') do Call %i %j

            Salmon Trout

            • Guest
            Re: Equivalent of Unix eval in Windows
            « Reply #8 on: December 15, 2009, 09:24:23 AM »
            I am getting confused myself. What is the result of including

            sb-config --env

            in a batch script?

            or typing it at the prompt?


            gpl



              Apprentice
            • Thanked: 27
              Re: Equivalent of Unix eval in Windows
              « Reply #9 on: December 15, 2009, 09:41:09 AM »
              From the original post

              Quote
              "sb-config --env" returns the commands to set some environment variables. The result is having multiples lines of SET commands.

              Salmon Trout

              • Guest
              Re: Equivalent of Unix eval in Windows
              « Reply #10 on: December 15, 2009, 09:45:27 AM »
              So you want to execute each line. What about this?
              Code: [Select]
              For /f "delims=" %%A in ('sb-config --env') do call %%A

              preeth

                Topic Starter


                Greenhorn

                Re: Equivalent of Unix eval in Windows
                « Reply #11 on: December 15, 2009, 11:51:39 PM »
                For /f "delims=" %%A in ('sb-config --env') do call %%A is working for me.

                Thanks gpl and Salmon.