How can I, in Windows, use the output of a script/command as an argument for another script?
(A pipe | will not work here, since that other script doesn’t read from the standard input)
Too clarify: I have AnotherScript that needs an argument arg, e.g.:
AnotherScript 12
now I want the argument (12 in the example) to come from the output of a script, call it ScriptB. So I would like something along the lines of
AnotherScript (ScriptB)
The AnotherScript is actually a python script that requires an argument, and ScriptB is a cygwin bash script that produces some number, so the way I would like to use it is something like:
c:\Python26\python.exe AnotherScript (c:\cygwin|bin|bash --login -i ./ScriptB)
Thanks for the answers. However, given the laborious ‘for’ construct required, I’ve rewritten AnotherScript to read from the standard input. That seems like a better solution.
Note: All this requires the commands to be in a batch file. Hence the double
%signs.You can use the
forcommand to capture the output of the command:then you can use that output in another command:
This will cause
%args%to contain the last line fromScriptB‘s output, though. If it only returns a single line you can roll this into one line:When used outside a batch file you have to use
%xinstead of%%x.However, if
ScriptBreturns more than one line,AnotherScriptruns for each of those lines. You can circumvent this—though only within a batch file—by breaking after the first loop iteration: