summaryrefslogtreecommitdiff
path: root/stdin-wrapper.bat
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2016-12-13 09:50:42 +0000
committerw0rp <devw0rp@gmail.com>2016-12-13 10:00:40 +0000
commit76a03b07099ec32135be4c7d9a7283343972b0af (patch)
tree25e5615b04347baccaa624601c94d1b581c872e9 /stdin-wrapper.bat
parent70e379cc46868916126156558486a8d8971cc5fa (diff)
downloadale-76a03b07099ec32135be4c7d9a7283343972b0af.zip
Add a Batch stdin wrapper script
Diffstat (limited to 'stdin-wrapper.bat')
-rw-r--r--stdin-wrapper.bat22
1 files changed, 22 insertions, 0 deletions
diff --git a/stdin-wrapper.bat b/stdin-wrapper.bat
new file mode 100644
index 00000000..eca8d717
--- /dev/null
+++ b/stdin-wrapper.bat
@@ -0,0 +1,22 @@
+@echo off
+
+REM Get a unique directory name in the temporary directory
+:loop
+set "directory=%tmp%\ale_%RANDOM%"
+if exist "%directory%" goto :loop
+
+REM Use a filename with the same file extension
+mkdir "%directory%"
+set filename="%directory%\file%1"
+
+REM Get all arguments after the first to run as a command
+for /f "tokens=1,* delims= " %%a in ("%*") do set command_args=%%b
+
+REM Read all stdin data to the filename
+more > "%filename%"
+
+REM Run the command on the file
+%command_args% "%filename%"
+
+REM Delete the temporary directory
+rmdir "%directory%" /s /q