Page 1 of 1

Conversion of batch to another language, then compile to an exe

Posted: 17 Oct 2016 16:09
by SirJosh3917
I was wondering if it was possible to take batch, convert it into another language that most resembles it, and then compile that into an exe.
Since most compilers just take it and throw it in %tmp%, I was wondering about actually converting the language to another language.
Could this be done?

One factor I have to realize however is batch's AMAZINGLY UNIQUE ability of this:

Code: Select all

@set a=asdf
@set %a%=Hello World
@echo %asdf%
::Outputs "Hello World"


which makes it hard to find a language that's similar.

Re: Conversion of batch to another language, then compile to an exe

Posted: 17 Oct 2016 18:01
by ShadowThief
All the major scripting languages can do that: bash, kornshell, Perl, Python, etc.

Perl and Python discourages this behavior because it really only exists to fill in for features that batch is missing, like actual arrays.

In terms of porting your batch script to another language, it mainly depends on what your script does, but there's a very good chance you can do it.

Re: Conversion of batch to another language, then compile to an exe

Posted: 17 Oct 2016 20:20
by penpen
It's not as easy, as it seems, (for example) because of funny things like this (simple example):

Code: Select all

@echo off
:bye  ^
echo Bye & goto :eof
call ^
:fun & call ^
:bye & goto :eof
echo Fun with batch.
goto :eof
:bye
"%~f0"
Just imagine what one could do by using "call ^
%label%"" lines, or if a line is a variable only, so the program flow depends on the actual value of that variable.)
So you first have to create an equivalent normed batch file, where the above things are not in use.


penpen

Re: Conversion of batch to another language, then compile to an exe

Posted: 20 Oct 2016 03:42
by foxidrive
In the same way that penpen discusses, batch files have so many undocumented techniques that a language conversion using autumated means is unlikely to be feasible.

Re: Conversion of batch to another language, then compile to an exe

Posted: 20 Oct 2016 04:24
by ShadowThief
foxidrive wrote:In the same way that penpen discusses, batch files have so many undocumented techniques that a language conversion using automated means is unlikely to be feasible.

But thankfully, them being undocumented means that most people don't know about them, which means that most people don't use them, which improves the likelihood that the script can be ported to another language.

Re: Conversion of batch to another language, then compile to an exe

Posted: 20 Oct 2016 18:42
by foxidrive
ShadowThief wrote:
foxidrive wrote:In the same way that penpen discusses, batch files have so many undocumented techniques that a language conversion using automated means is unlikely to be feasible.

But thankfully, them being undocumented means that most people don't know about them, which means that most people don't use them, which improves the likelihood that the script can be ported to another language.


Undocumented techniques are used everywhere in DosTips. In fact it's what everyone here enjoys - in wringing out new ways of abusing commands.

MUF17.ZIP is a file compiled by a bloke named Bat Lang. Microsoft Undocumented Features is what MUF stands for.

Them were the good old days, :)

Re: Conversion of batch to another language, then compile to an exe

Posted: 20 Oct 2016 21:03
by Squashman
You are apparently think the Holy Grail exists.

Re: Conversion of batch to another language, then compile to an exe

Posted: 21 Oct 2016 02:34
by ShadowThief
foxidrive wrote:
ShadowThief wrote:
foxidrive wrote:In the same way that penpen discusses, batch files have so many undocumented techniques that a language conversion using automated means is unlikely to be feasible.

But thankfully, them being undocumented means that most people don't know about them, which means that most people don't use them, which improves the likelihood that the script can be ported to another language.


Undocumented techniques are used everywhere in DosTips. In fact it's what everyone here enjoys - in wringing out new ways of abusing commands.

MUF17.ZIP is a file compiled by a bloke named Bat Lang. Microsoft Undocumented Features is what MUF stands for.

Them were the good old days, :)

True, but a good chunk of that was simply to replicate functionality that most other languages have, so it should still work (in theory). Again, it really depends on the code they're trying to port.

Re: Conversion of batch to another language, then compile to an exe

Posted: 21 Oct 2016 13:06
by foxidrive
ShadowThief wrote:it really depends on the code they're trying to port.

I think I drifted off onto automated conversion but manual porting of code should be doable.

Automated conversion of simple scripts might work...without any reliability and it would be a case of suck-it-and-see.