Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BASH Backquote equivalence in cmd.exe? 1

Status
Not open for further replies.

rayen99

Technical User
Sep 7, 2002
74
US
Does anybody know the command substitution syntax for the windows command line? Or is there not one?
 
Do you mean how do you get to the dos prompt?

if so - Start Run, CMD or command or comand.com will
work.

cheers
 
Thanks, but yeah I don't mean that. I want to substitute the output of one command as a parameter of another. For example in the BASH shell you could type something like "rm `cat del.txt`" and if the contents of del.txt were "number.txt" and number.txt was in the current folder it would be deleted.
 
If your output is going to a file, then you can read the output using for /f and run commands against it. It's a bit of a gnarly command for getting the syntax right, but here's reading from a file with a single parameter per line:

FOR /F &quot;eol=; tokens=1* delims= &quot; %i in (myfile.txt) do <command> %i

If you run it from a batch, those variables need double percent signs ie: %%i. Substitute <command> for the actual command. The %i is a convention - if you have more than one token/parameter per line, they become %j, %k, etc etc

You can capture output directly from a command and use it to execute something too:

FOR /F &quot;usebackq delims==&quot; %i IN (`<command>`) DO <anothercommand> %i

I suggest you run help for in the command prompt and see all the gubbins it goes on about...


PS. And if you need to really convoluted processing of the input/output, I suggest you just use Perl ;-)
 
Thanks a lot for the help billieT. Hmm I figured there would be an easier way to do that, but hey your method works. Awesome, thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top