Make cmd.exe parse piped batch code

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BoQsc
Posts: 81
Joined: 30 Jun 2014 04:10

Make cmd.exe parse piped batch code

#1 Post by BoQsc » 22 Mar 2020 08:31

Is it possible to make cmd.exe to parse piped batch code?
Are there ways to process piped batch code?
There seems to be conflicts between cmd interpreter syntax and batch syntax.

PS. I'm not talking about running a batch script. I'm talking about running the piped batch code.

If not:
Are there any converters that could convert batch script to a cmd.exe directly interpretable code?

carlos
Expert
Posts: 501
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Make cmd.exe parse piped batch code

#2 Post by carlos » 22 Mar 2020 10:00

Hello.

Cmd.exe run code in two modes:
- interactive
- script

some differences between them: interactive not support goto labels and for variables use a single percent character (%) %a vs %%a.
Thus you can run some code as pipe to cmd.exe but with limitations, not code expected to run in batch mode, because in this case cmd will interpret it in interactive mode.

Example:

Code: Select all

C:\Users\Carlos>(echo vol & exit) | cmd
Microsoft Windows [Version 10.0.xxxxx.xxx]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Carlos>vol
 Volume in drive C has no label.
 Volume Serial Number is XXXX-XXXX

C:\Users\Carlos>
Cmd displays the windows version at the begin, because is executed in interactive mode, thus is not practical.

Aacini
Expert
Posts: 1647
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: Make cmd.exe parse piped batch code

#3 Post by Aacini » 04 Apr 2020 12:01

All the differences between "execute a batch script" vs. "execute command lines piped/redirected to cmd.exe" are described with detail at this thread.

Antonio

Post Reply