-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathxargs.bat
73 lines (53 loc) · 1.56 KB
/
xargs.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@echo off
setlocal
if /i (%1)==(/?) goto USAGE
if /i (%1)==() goto USAGE
if /i (%1)==(/addquotes) goto ADDQUOTES
goto NOQUOTES
:USAGE
echo usage: something-that-produces-output ^| %0 [/?] [/addquotes] thing-to-run
echo xargs.bat by Matthew van Eerde 10/3/2005
echo.
echo something-that-produces-output should write to its STDOUT
echo thing-to-run will have each line of the output appended to it,
echo then will be run successively
echo.
echo If /addquotes is set, quotes will be added around the line
echo before appending the line to thing-to-run
echo.
echo If you call xargs without piping output to it, xargs will wait
echo for you to type something in on STDIN.
echo Ctrl-Z on its own line to finish.
goto END
:ADDQUOTES
rem eat /addquotes parameter
shift
rem Alas, shift doesn't affect %*
if (%1)==() goto USAGE
set basecommand=%1
shift
:BUILDBASECOMMAND
if (%1)==() goto DONEBASECOMMAND
set basecommand=%basecommand% %1
shift
goto BUILDBASECOMMAND
:DONEBASECOMMAND
rem run the program specified by %*
rem as many times as there are lines in STDIN
rem with one extra argument -- defined by each line of STDIN -- in quotes
rem
rem all that the find command does is intercept STDIN
rem
for /F "usebackq delims=" %%a in (`find /v ""`) do %basecommand% "%%a"
goto END
:NOQUOTES
rem run the program specified by %*
rem as many times as there are lines in STDIN
rem with extra arguments defined by each line of STDIN
rem
rem all that the find command does is intercept STDIN
rem
for /F "usebackq delims=" %%a in (`find /v ""`) do call %* %%a
goto END
:END
endlocal