Any way for a windows cmd script to set a var from the output of an app? - Programmer

This is a discussion on Any way for a windows cmd script to set a var from the output of an app? - Programmer ; In Windows CMD scripts, is there any way to set a variable to the output of an application? I wrote a short perl script that produces a string I want to set into a variable in a CMD script. I ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Any way for a windows cmd script to set a var from the output of an app?

  1. Any way for a windows cmd script to set a var from the output of an app?

    In Windows CMD scripts, is there any way to set a variable to the
    output of an application? I wrote a short perl script that produces a
    string I want to set into a variable in a CMD script. I don't see any
    way in the syntax of SET, or anything else, to do this.


  2. Re: Any way for a windows cmd script to set a var from the outputof an app?

    davidmichaelkarr@gmail.com wrote:
    > In Windows CMD scripts, is there any way to set a variable to the
    > output of an application? I wrote a short perl script that produces a
    > string I want to set into a variable in a CMD script. I don't see any
    > way in the syntax of SET, or anything else, to do this.
    >


    FOR /F "usebackq tokens=1" %%v IN (`myprog.exe`) DO (
    SET VAR=%%v
    )

    This will execute myprog.exe and parse each line of output into space
    delimited fields. The value of the environment variable VAR will be
    repeatedly set to the first field of each line. (Assuming only one line
    of output and one space delimited field in the output, this does what
    you want.)

    If the output that you want to capture may contain spaces, use this instead:
    FOR /F "usebackq tokens=1*" %%v IN (`myprog.exe`) DO (
    SET VAR=%%v %%w
    )

    But, doesn't Perl have an intrinsic command for setting environment
    variables?

    Norm

    --
    --
    To reply, change domain to an adult feline.


+ Reply to Thread