Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

windows subcommand evaluation

linux & unix shells can process subcommands like this.

$> command `subcommand`

does windows cmd shell similar feature?

like image 305
mert Avatar asked Aug 04 '10 18:08

mert


2 Answers

You can get something similar using a variation of the for command:

FOR /F "usebackq tokens=*" %%a IN (`subcommand`) DO @command %%a

One big difference (besides being unintuitive and much uglier) is that it'll execute command once for each line produced by subcommand

Note that inside a script file, the percent signs must be doubled up (use non-doubled percent signs if you have some reason to want to do this at the command line).

like image 199
Michael Burr Avatar answered Nov 19 '22 04:11

Michael Burr


As a whole, no. The Windows Command Prompt really isn't much of a shell in that it doesn't provide much functionality of its own, independent from the commands that you can run. For example, in most Un*x shells, file globbing (matching foo.* to a list of files) is handled by the shell itself. In Windows, every application sees the foo.* from the command line and has to implement the file globbing on its own.

If you're moving down the road of trying to automate Windows, or want a more full-featured shell, you should consider using PowerShell, which does let you do sub-commands:

command (subcommand)

like image 24
JaredReisinger Avatar answered Nov 19 '22 03:11

JaredReisinger