Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
SirJosh3917
- Posts: 36
- Joined: 02 May 2016 18:59
#1
Post
by SirJosh3917 » 17 Oct 2016 16:09
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.
-
ShadowThief
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
#2
Post
by ShadowThief » 17 Oct 2016 18:01
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.
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#3
Post
by penpen » 17 Oct 2016 20:20
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
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#4
Post
by foxidrive » 20 Oct 2016 03:42
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.
-
ShadowThief
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
#5
Post
by ShadowThief » 20 Oct 2016 04:24
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.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#6
Post
by foxidrive » 20 Oct 2016 18:42
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,
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#7
Post
by Squashman » 20 Oct 2016 21:03
You are apparently think the Holy Grail exists.
-
ShadowThief
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
#8
Post
by ShadowThief » 21 Oct 2016 02:34
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.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#9
Post
by foxidrive » 21 Oct 2016 13:06
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.