Convert batch script into an executable or higher language

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
terus
Posts: 14
Joined: 26 Apr 2013 22:40

Convert batch script into an executable or higher language

#1 Post by terus » 02 May 2013 02:03

Second EDIT:
I've been looking at C# and mono as the most likely candidate for my ventures.


EDIT:
I kind of babeled a bit in the OP & strayed from the points a bit.

In short, can batch scripts be converted to other programming languages? If not what might be the best alternative language to start with? Is there potential for a simple cross platform solution?
--------

OP:
First off, sorry if this is a little out of place on here. I'm not really sure where else to ask this. But I was wanting to know if anyone might have a suggestion. I have what is in essence a set of programs, or utilities even, made from batch scripts.

What I would like to know is how I might go about traversing the batch files into executables. I know bat to exe software exists. But honestly everything I've tried is fairly faltered when using call or goto arguments. Which I do quite often as I like to script in a manner that requires it. In essence making several sub routines as it were.

Don't get me wrong the batch files work well as is. I would just like to be able to have embedded icons, versioning information, etc... so as to make public release a little more professional. Is there maybe a way to convert batch script into source code for any other programming language? My searches have been less than promising. Perhaps someone here knows something more on the matter.

Perhaps my question should be; What might the best suited programming language be as the next logical step? Preferably something without too steep a learning curve. I wet my toes a bit with qbasic many years ago. Though that may be just a little to dated by now. A friend of mine had suggested tk/tcl but, to my knowledge, that's a little more suited for *nix environments & not my target audience. Though cross platform compatibility is definitely a good idea. Sorry I'm babeling a bit now.

I appreciate any suggestions or info anyone may present. Thanks in advance.
Last edited by terus on 02 May 2013 02:26, edited 1 time in total.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Convert batch script into an executable or higher langua

#2 Post by abc0502 » 02 May 2013 02:20

To convert Batch to EXE

Free Software: Link
Never Had Problems with, can add version number, icons, and other files can be added with.
but any one can easily see the source if used any archive manager like 7z.

Paid Software: Link
Like the above but it can secure your exe, no one can see the source

terus
Posts: 14
Joined: 26 Apr 2013 22:40

Re: Convert batch script into an executable or higher langua

#3 Post by terus » 02 May 2013 02:41

Unfortunately batch to exe by F2KO is the primary converter I have been trying to use. CALL and GOTO seem to break it. Especially when calling anything external. Also use of IF EXIST causes problems as well. The .bat files work nearly flawlessly but once converted they crash & close often.

I wondered if it was a programming issue at first. But when rechecking my .bat files everything worked without incident. So I wrote test scripts to see what specific functions were causing this. The primary problem is IF EXIST regardless of syntax. I even tried adding IF NOT instead of ELSE. Also tried just IF EXIST on its own. For what ever reason that function, or command rather, does not like to work well. It seems that the scripts all work well when opened from within explorer. But for what ever reason falter when opened from the command prompt. Or converted to exe. It even crashed when I made a conversion that called a bat file containing an IF EXIST statement. Trying of course with the existence being both true & false alternatively. I would assume the conversion opens things in the same manner as cmd.exe. Perhaps I should have made a post to try & fix that first. Though if it can't be fixed I think I'm probably hooped far as conversion goes. Most likely best off starting over in another language. Much as I'd rather not.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Convert batch script into an executable or higher langua

#4 Post by abc0502 » 02 May 2013 02:57

I never had problems with it, the only reason your if command or call and goto when calling external files is because you must forgot that it extract the batch to a different directory ( usually %temp% in a random folder name ) so it won't exist in %temp% but in %temp%\{random number.tmp}

terus
Posts: 14
Joined: 26 Apr 2013 22:40

Re: Convert batch script into an executable or higher langua

#5 Post by terus » 02 May 2013 05:05

Oh, well that changes things quite a bit. Is there a way to direct the path back to the primary opening folder? If the folder is to change & be primarily unknown to the coder/programmer. If not is there a way to force the temp folder to something specific that can be worked with? A constant rather than a generated random. Even if initial name/path is generated randomly.

Thought I might add that the compressed archive utility loop hole doesn't bother me at all. People can have a look at the source if they see fit. I have nothing to hide. Just want the embedded features an executable can provide.

Also wanted to thank you again. You have been most informative & very helpful.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Convert batch script into an executable or higher langua

#6 Post by abc0502 » 02 May 2013 05:33

You can always change the current path using the CD command, with the /D switch.
Try it

Code: Select all

CD /D "{Path Goes here}"
try it might help

also, to get the current directory that the batch run from "%%~dp0"
but note that it return the current path and ends with a back-slash "\" so don't put extra one between the path and any file/folder name you put.

terus
Posts: 14
Joined: 26 Apr 2013 22:40

Re: Convert batch script into an executable or higher langua

#7 Post by terus » 02 May 2013 06:31

The reason I need, or perhaps want, to call an external file is 2 fold. First off I'm using it as a first run test. Next the external file is used to store file & folder path variables. I wanted to keep it in the same/original folder. To give the end user the option to easily find & edit the variables in an external editor. If they choose to. However once I incorporate a GUI into the configuration utility that won't matter anyway.

Code: Select all

REM First RUN Test
:firstrun
if exist {variables.bat} (
   call variables.bat
) else (
   call :setpath
   )
goto :eof


I've used the path/file stuff before. Specifically to change the function of a batch based on its filename. May seem a little crazy. But they both do the same thing, one with confirmation before everything & the other without any. That's the outcome of my previous post involving the loops. Though I couldn't get it to work without setting it as a variable first. Perhaps that would be due to having one '%' rather than two. I'll look into that later.

Code: Select all

REM Determin if launch or install
:instype
pause
@echo on
set instype=%~n0
if /i {%instype%}=={install} (call :install )
if /i {%instype%}=={launch} (call :launch )
pause
goto :eof



Anyway that's getting a little off topic. Basically, from what I understand, if I want to use external files after conversion. I'll have to use a temp folder. That I specifically have to hardcode into the source. Since the existing temp folder made by the executable is set randomly each run. And there's no way of knowing where the executable was launched from.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Convert batch script into an executable or higher langua

#8 Post by abc0502 » 02 May 2013 06:44

The Application that convert the batch to EXE is just compress the main batch files and all files you add using the include tab.
They all extracted in "%temp%\{randomNumber}.tmp\" folder
but as they all in the same folder there shouldn't be any problems. :?

And Perhaps you have to provide full path of all of your files you use in your batch
If you can post the code perhaps we could help.

terus
Posts: 14
Joined: 26 Apr 2013 22:40

Re: Convert batch script into an executable or higher langua

#9 Post by terus » 02 May 2013 07:33

The external file variables.bat is generated from user input. When it doesn't exist, configuration is launched to generate variables.bat. Since I don't want that to happen every time the primary file is launched. I'll need to define my own temp folder for it. Unless there is a way to find the folder the exe was opened from. Then either save the externally generated content/file to that folder or add it into the compressed executable.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Convert batch script into an executable or higher langua

#10 Post by abc0502 » 02 May 2013 07:50

I see now, so it's like an ini file that hold settings for the batch for future execution.
It must be as you said in a known folder, like in C:\AppName\
and your main batch has that path coded inside it

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

Re: Convert batch script into an executable or higher langua

#11 Post by carlos » 02 May 2013 12:07

Currently I'm programming a "batch compiler". It is different from all current batch compilers, because it never write the source code to hard disk.

terus
Posts: 14
Joined: 26 Apr 2013 22:40

Re: Convert batch script into an executable or higher langua

#12 Post by terus » 02 May 2013 16:43

Would I be better off with an ini? I'm not quite sure how to write or call something like that. In a manner where it would set file & folder path related variables. I should perhaps rename it paths.ext as well.

Actually nevermind... This is getting to be an exercise in hand holding. I'll go see what I can figure out. Thanks for all the help & insight!


@abc0203
Yeah sorry I wasn't clear enough on that. It was kind of implied but never stated.

@carlos
That would be awesome. Please keep me informed on progress. So long as there's no nag screen or something like a watermark. I would gladly pay for that ability, or donate if you chose to go that route.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Convert batch script into an executable or higher langua

#13 Post by abc0502 » 03 May 2013 03:17

If you want the file to hold setting, it doesn't matter what kind of file it is, it could be ini, ext. exe, or even without extensions.
The batch file just read what inside and take that as an input and work based on it.

So name it .ini, .exe, .txt any thing, just make sure you can extract inputs from it by knowing which line contain what setting.

terus
Posts: 14
Joined: 26 Apr 2013 22:40

Re: Convert batch script into an executable or higher langua

#14 Post by terus » 08 May 2013 16:41

I'm not quite sure what I'm doing far as that goes. Reading/writing & not overwriting but still keeping everything on the correct lines. Instead I just have the output set in a manner that the external file runs as a script & sets variables when called. I'm sure there's more efficient ways of storing settings externally. But this works for now & I'll implement something better when I iron everything else out. If I don't abandon the script for public release. As it is I'm having a hard enough time with other stuff. Never realized how difficult it was making things user friendly & idiot-proof. Honestly the more I work on this the more it seems I should just write a proper piece of compiled software. So many things in batch scripts that you have to force to work. Often times going outside the capabilities of CMD on its own.

I've been playing a bit with Mono GTK#. Seems to be pretty well what I should be using for something this complex.

Sorry I do realize that talking about alternative languages is off topic for this forum. I will refrain from that from now on.

Thanks for all the help you've given me with my batch woes. I'd probably still be scratching my head without it.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Convert batch script into an executable or higher langua

#15 Post by foxidrive » 08 May 2013 21:51

terus wrote:Honestly the more I work on this the more it seems I should just write a proper piece of compiled software. So many things in batch scripts that you have to force to work.


Yes, you're right. :) Batch is great when you can control the input in terms of text characters and you know the version of Windows, and the date and time are known formats. But it's damn hard to make many batch files universal, where they will work on any machine.

Post Reply