Search code examples
windowshttp-redirectbatch-fileechoexecute

Windows 7 Batch: Execute the Output of ECHO


For some reason, this question was closed due to generality. It is, however, a specific question about batch scripting. I have edited to try to make that clearer.

Specifically, I want a batch file to run a command like this today:

start Firefox "http://www.billboard.com/charts/hot-100?chartDate=2012-12-01"

But tomorrow the date will be advanced by one day. That is, tomorrow's command will look like this:

start Firefox "http://www.billboard.com/charts/hot-100?chartDate=2012-12-02"

I have devised a batch file with these two lines:

set BBURL=start Firefox "http://www.billboard.com/charts/hot-100?chartDate=%date:~10,4%-%date:~4,2%-%date:~7,2%"
echo %BBURL%

These lines give me the command I want, updated each day as shown above. But they don't actually run the command. So my questions are:

  1. Is there a better way to do this?
  2. How can I redirect or execute the "echo %BBURL%" output so that it runs as a command?
  3. What is the proper syntax if I want to alter the command to specify a date in the past (e.g., same day of the year, but 10 years earlier)?

Solution

  • Can't you just do:

    set BBURL=start Firefox "http://www.billboard.com/charts/hot-100?chartDate=%date:~10,4%-%date:~4,2%-%date:~7,2%"
    %BBURL%