Created
October 29, 2009 04:39
-
-
Save brettz9/221161 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Don't hold me accountable if this is not safe! This is my first batch | |
:: file beyond just opening programs... | |
:: When used in conjunction with http://gist.github.com/221159 , Firefox | |
:: can call this file with the first argument being a file to which to log | |
:: output (error or otherwise), thus enabling applications like command-line | |
:: emulators in Firefox | |
:@echo off | |
:: First argument is the output file, the second argument is the command (e.g., "svn"), and the other arguments up to the last are arguments to be passed after the command, and the last argument is the argument count and is ignored | |
:: The file to be used for output | |
SET "outputFile=%1" | |
:: If there are no arguments after the file, then we will choose 'help' below as the default argument | |
SET "firstArg=%2" | |
SET args= | |
:: Let %1 refer to %2 | |
SHIFT | |
:: Cycle through any number of arguments | |
:Loop | |
:: If the current argument is blank, we're done | |
IF "%1"=="" GOTO Continue | |
echo "okk: %args%" | |
:: Store our argument temporarily | |
SET arg=%1 | |
:: Concatenate | |
SET "args=%args% %arg%" | |
:: Let %2 refer to %3, etc. | |
SHIFT | |
:: Start the cycle over | |
GOTO Loop | |
:Continue | |
:: Set a default command of "help" if none supplied (might also just execute without flags (or output?) | |
IF "%firstArg%"=="" (GOTO help) ELSE (GOTO noset) | |
:help | |
:: Set the default (could just use the "outputFile" as the argument (interpret it as executable) and do not output to file, but would be potentially confusing | |
set "args=help" | |
GOTO noset | |
:noset | |
::pause | |
:: Invoke command (must be in PATH) with passed-in arguments and output results to the file argument; the piping + "more" ensures "standard error" stream gets written to file too | |
%args% 2>&1 | more > %outputFile% | |
::pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment