Page 1 of 1

Make cmd.exe parse piped batch code

Posted: 22 Mar 2020 08:31
by BoQsc
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?

Re: Make cmd.exe parse piped batch code

Posted: 22 Mar 2020 10:00
by carlos
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.

Re: Make cmd.exe parse piped batch code

Posted: 04 Apr 2020 12:01
by Aacini
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