Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 

Sign in to follow this  
TuMaGoNx

Portabat (Portable Batch Environment)

Recommended Posts

TuMaGoNx    48

Introducing portabat https://github.com/tumagonx/portabat

This is custom 7zsfx (7zip SDK 17.00) that make your batch more realistically like an executable. Try demo here https://github.com/tumagonx/portabat/releases

Editing:
All you need is open portabat-test.exe with 7zip and edit hello.bat or add your own batch, no need to copy /b or create config.txt. See filename execution order from homepage

Requirement: XP or later

Note:
ReactOS cmd is about 95% compatible, if you're batch nerd you can see few different quirks behavior compared to windows cmd
separate 7z.sfx available at https://github.com/tumagonx/portabat/raw/master/basebin/7z.sfx (about 20KB if packed)

Suggestions are welcome!

Share this post


Link to post
Share on other sites
jaclaz    926

Interesting. :)

You could really spend a few words (on the site) explaining how it works (not really how it works, but how one can create a self extracting archive with that).

Is the roscmd "needed" or it is only in the case one want to workaround command execution policies?

Or if you prefer, which of the zillion files in the example are actually *needed*?

Maybe - besides the example - you could provide an "empty", "bare minimum" template?

Any way to ONLY open a command prompt?

Or, if you prefer, to drop to command line once the batch has been executed OR interrupted and then need to type EXIT to close the command window?

I mean without directly invoking %~dp0\roscmd.exe? (like an internal .ini file with a setting *like* DropToDos=1)

Also there is an issue. :w00t::ph34r:

In the roscmd.exe window the ALT+code seemingly does not work , which plainly means that on an Italian keyboard (but I suspect on many other ones) I cannot input the tilde ~ on command line (that is ALT+0126),

Yes, I know I can run %comspec% /? and that I can do SET Mydir=%comspec:\roscmd.exe=% and cd /d %mydir%, but it is a big limitation, as I see it.

By the same token of the "DropToDos", it would be nice to have in the (hypothetical) .ini settings file the option to choose whether to run in the directory where the .exe is (i.e. %SFXPATH%) or in the directory where the sfx is temporarily extracted (i.e. %~dp0),

In any case pushd %mydir% and popd work just fine :thumbup.

jaclaz

 

 

Edited by jaclaz

Share this post


Link to post
Share on other sites
TuMaGoNx    48

Is the roscmd "needed" or it is only in the case one want to workaround command execution policies?
+1
Right, I should check the policy registry before launching batch and use system cmd if ok
roscmd is base requirement ATM, my plan is to merge some external helpers program into internal ReactOS command, but it's bad idea as it promote non-standard practice.

Or if you prefer, which of the zillion files in the example are actually *needed*?
No idea, I think batch is good for file processing so those related to that

Any way to ONLY open a command prompt?
That not what batch file behave no? it also behave like usual 7zsfx, aka simply having only roscmd.exe inside the SFX will simply launch it (command prompt) (rename roscmd.exe to setup.exe to get priority if other exes presents)

Or, if you prefer, to drop to command line once the batch has been executed OR interrupted and then need to type EXIT to close the command window?
I try to make it behave like regular batch, quit after done, it's batch author consideration to add pause/%COMSPEC%

By the same token of the "DropToDos", it would be nice to have in the (hypothetical) .ini settings file the option to choose whether to run in the directory where the .exe is (i.e. %SFXPATH%) or in the directory where the sfx is temporarily extracted (i.e. %~dp0),
Same above, I try to be consistent with default batch behavior it would be CWD=SFXPATH or CWD=CWD of the caller (aka called from existing cmd box), thus up to author to switch into %~dp0


You could really spend a few words (on the site) explaining how it works (not really how it works, but how one can create a self extracting archive with that).
I will create smaller template, I try avoid explaining "you need to: copy /b 7z.sfx+archive.7z mybatch.exe" :D
my hope is people use 7zip file manager to edit the batch or drag and drop their batch into it.

Thanks for the inputs, it's a shame about the keyboard issue, I guess you spot new incompatibility in roscmd

judging the way you asks it seems you concern more how to work in roscmd box instead of run batch file? do you have different use cases?

Share this post


Link to post
Share on other sites
jaclaz    926

The point is just that to write a batch file you (actually I) normally test the command in the exact same environment where the batch will be run, not really an issue (for me) but a potential user will (in this order):

1) add his/her batch file AND remove the roscmd.exe from the archive (FAIL)

2) add his/her batch file AND NOT remove the roscmd.exe BUT have no PAUSE in the batch (FAIL)

3) add his/her batch file AND NOT remove the roscmd.exe AND have PAUSE in the batch BUT the batch only works in CMD.EXE (FAIL)

Personally I hate programs that "decide" what is better for me, where a simple file with a few settings would allow me to decide myself what is better on a case by case basis.

Actually when/if the little ROSCMD.EXE incompatibilities will be "leveled out" it is actually "better" (IMHO) to use that command processor (and also "guaranteed" executables inside the 7-zip sfx), so that the batch (tested on that command processor and with that exact version of the other .exe's) surely works, avoiding possible incompatibilities between different CMD.EXE's on different OS's, including a few related to localization.

A teeny-tiny issue with Roscmd.exe is the different behaviour of PUSHD.

On Windows CMD.EXE once you have PUSHD a directory, running PUSHD without arguments will show the pushed directory, on ROSCMD, it doesn't, this may "break" some particular batches, this is a workaround for tilde assigning the variable %sfxextpath% so that it can be typed and the variable tilde:

myhello.cmd:

@echo off
title %SFXPATH%%SFX%
SET SFXEXTPATH=%~dp0
SET SFX
SET TILDE=~
SET TILDE
%~dp0\roscmd.exe

then (output and commands):

SFX=mytest.exe
SFXEXTPATH=C:\DOCUME~1\jaclaz\IMPOST~1\temp\7z14024E48\
SFXPATH=C:\batches\Portabat\

ReactOS Operating System [Version 0.4.5 20170801-rUNKNOWN]
(C) Copyright 1998-2017 ReactOS Team.

C:\batches\Portabat>pushd %sfxextpath%

C:\Documents and Settings\jaclaz\Impostazioni locali\temp\7z14024E48>pushd

C:\Documents and Settings\jaclaz\Impostazioni locali\temp\7z14024E48>popd

C:\Documents and Settings\jaclaz\Impostazioni locali\temp\7z14024E48>popd

C:\batches\Portabat>cmd.exe
Microsoft Windows XP [Versione 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\batches\Portabat>set sfx
SFX=mytest.exe
SFXEXTPATH=C:\DOCUME~1\jaclaz\IMPOST~1\temp\7z14024E48\
SFXPATH=C:\batches\Portabat\

C:\batches\Portabat>pushd %sfxextpath%

C:\DOCUME~1\jaclaz\IMPOST~1\temp\7z14024E48>pushd
C:\batches\Portabat

C:\DOCUME~1\jaclaz\IMPOST~1\temp\7z14024E48>popd

C:\batches\Portabat>

 

Another side-side note (very minor) is that traditionally .bat should be compatible with DOS/9x, while .cmd is the extension for batches to be executed by CMD.EXE (or ROSCMD.EXE).

jaclaz

 

Share this post


Link to post
Share on other sites
TuMaGoNx    48

Actually when/if the little ROSCMD.EXE incompatibilities will be "leveled out" it is actually "better" (IMHO) to use that command processor (and also "guaranteed" executables inside the 7-zip sfx), so that the batch (tested on that command processor and with that exact version of the other .exe's) surely works, avoiding possible incompatibilities between different CMD.EXE's on different OS's, including a few related to localization.

Originally that's what I thought, but also realized the "no guarantee to run" issue is dilemma. Yet you found even more incompatibility :) (though ReactOS also under development)
I think exe less than 50KB will be bundled by default (like now) but will be put in its own folder


Another side-side note (very minor) is that traditionally .bat should be compatible with DOS/9x, while .cmd is the extension for batches to be executed by CMD.EXE (or ROSCMD.EXE).

Oops my bad habit, but this is also dilemma for those born with XP or later experience (like me)

Share this post


Link to post
Share on other sites
jaclaz    926

Yes, it was only to show a possible issue in "inserting a batch tested on cmd,exe", if you (IMHO wrongly) implement the "autodetect policies" there would be no certainties about which command processor is used, and thus a same batch file may work fine in a machine and not work on another one because two different command processors are run depending on the autodetection.

As said, no matter which small quirks this or that command processor .exe, they don't really matter, as long as the batch has been tested on that specific command processor.

In this the "embedded" command processor is a very good idea. :thumbup

Putting it in a subdirectory of the 7-zip is (still IMHO) not only unneeded, but also an unneeded complication, however. :(

What would be useful would be to be able to change the command processor, so that we are not limited to ROSCMD.EXE, as an example one might want to use 4NT/TCCLE:

https://jpsoft.com/tccle-cmd-replacement.html

http://www.portablefreeware.com/forums/viewtopic.php?t=3392

or Greg's Shell:

https://www.gammadyne.com/cmdline.htm#gs

or whatever other alternative command line processor, including (of course not for redistribution) a copy of a Windows CMD.EXE.

Again, a simple .INI file with a number of simple choices possible would add greater flexibility without making anyway the thing too complex.

Here is another quirk, this one serious, it seems like ROSCMD does not exits loops :w00t::ph34r::

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL ENABLEEXTENSIONS

FOR /L %%A IN (0,1,5) DO (
SET Number=%%A
IF %%A==2 GOTO :out_of_loop
IF %%A==2 ECHO %%A IS equal to 2
ECHO %%A IS NOT equal to 2
)
GOTO :EOF

ECHO.
ECHO You won't see this

:out_of_loop
ECHO Here is out of loop, number is %number%
C:\>looptest.cmd
0 IS NOT equal to 2
1 IS NOT equal to 2
Here is out of loop, number is 2

C:\>roscmd

ReactOS Operating System [Version 0.4.5 20170801-rUNKNOWN]
(C) Copyright 1998-2017 ReactOS Team.

C:\>looptest.cmd
0 IS NOT equal to 2
1 IS NOT equal to 2
2 IS equal to 2
2 IS NOT equal to 2
3 IS NOT equal to 2
4 IS NOT equal to 2
5 IS NOT equal to 2
Here is out of loop, number is 5

C:\>exit

jaclaz

Share this post


Link to post
Share on other sites
roytam1    18
1 hour ago, jaclaz said:

Yes, it was only to show a possible issue in "inserting a batch tested on cmd,exe", if you (IMHO wrongly) implement the "autodetect policies" there would be no certainties about which command processor is used, and thus a same batch file may work fine in a machine and not work on another one because two different command processors are run depending on the autodetection.

As said, no matter which small quirks this or that command processor .exe, they don't really matter, as long as the batch has been tested on that specific command processor.

In this the "embedded" command processor is a very good idea. :thumbup

Putting it in a subdirectory of the 7-zip is (still IMHO) not only unneeded, but also an unneeded complication, however. :(

What would be useful would be to be able to change the command processor, so that we are not limited to ROSCMD.EXE, as an example one might want to use 4NT/TCCLE:

https://jpsoft.com/tccle-cmd-replacement.html

http://www.portablefreeware.com/forums/viewtopic.php?t=3392

or Greg's Shell:

https://www.gammadyne.com/cmdline.htm#gs

or whatever other alternative command line processor, including (of course not for redistribution) a copy of a Windows CMD.EXE.

Again, a simple .INI file with a number of simple choices possible would add greater flexibility without making anyway the thing too complex.

Here is another quirk, this one serious, it seems like ROSCMD does not exits loops :w00t::ph34r::


@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL ENABLEEXTENSIONS

FOR /L %%A IN (0,1,5) DO (
SET Number=%%A
IF %%A==2 GOTO :out_of_loop
IF %%A==2 ECHO %%A IS equal to 2
ECHO %%A IS NOT equal to 2
)
GOTO :EOF

ECHO.
ECHO You won't see this

:out_of_loop
ECHO Here is out of loop, number is %number%

C:\>looptest.cmd
0 IS NOT equal to 2
1 IS NOT equal to 2
Here is out of loop, number is 2

C:\>roscmd

ReactOS Operating System [Version 0.4.5 20170801-rUNKNOWN]
(C) Copyright 1998-2017 ReactOS Team.

C:\>looptest.cmd
0 IS NOT equal to 2
1 IS NOT equal to 2
2 IS equal to 2
2 IS NOT equal to 2
3 IS NOT equal to 2
4 IS NOT equal to 2
5 IS NOT equal to 2
Here is out of loop, number is 5

C:\>exit

jaclaz

I'd just opened a ros jira ticket: https://jira.reactos.org/browse/CORE-13713

Edited by roytam1

Share this post


Link to post
Share on other sites
TuMaGoNx    48

Holy sh*t thats serious one!
frankly during my test I only knew that START has different behavior as it only wait child process depends on whether it is console/window executable

"Putting it in a subdirectory of the 7-zip is (still IMHO) not only unneeded, but also an unneeded complication, however."
because it quickly become cramped... root will be only for batches and user data, the exe subdir automatically *pre-pended* in %PATH% before %COMSPEC% run (so no complication, you still called them just by name)

yes I'm aware of tcc and greg but, I don't naturally mess with non-OSS :D

I will think about the ini file

Share this post


Link to post
Share on other sites
TuMaGoNx    48

Added windows update lister
Before this I use OnePiece Get_Microsoft_Update_List.exe but it doesn't show url which I want to feed the output to curl/wget in automated batch downloading

getwu

will fetch download link per line

getwu -v

will show additional info of each update

download
https://github.com/tumagonx/portabat/raw/master/minbin/getwu.exe (6.5KB)

Share this post


Link to post
Share on other sites
TuMaGoNx    48

Add more info in getwu

example:
getwu -v

Searching for updates ...
List of applicable items on the machine:

1. Windows Media Player 11 (for Windows XP Professional x64 Edition)
Size=27936568
Date=Tue Apr 22 00:00:00 2008
Priority=2
Delta=0
Beta=0
Action=1
ID=40394e2a-1935-4233-8171-b4c5b85e67ec
Download URL(s):
http://www.download.windowsupdate.com/msdownload/update/v3-19990518/cabpool/wmp11-windowsxp-x64-enu_35583b427a7488e386998c6dd2c3b71d68c3c1ae.exe

2. Windows Search 4.0 for Windows XP x64 Edition (KB940157)
Size=8840208
Date=Tue Jul 22 00:00:00 2008
Priority=2
Delta=0
Beta=0
Action=1
ID=46e24996-7f60-46a4-b14c-8e7340375068
Download URL(s):
http://www.download.windowsupdate.com/msdownload/update/software/ftpk/2008/06/windowssearch-kb940157-srv2k3_xp-x64-enu_774aa531cfd4d7f7baf3d2b8011f4da551975bf4.exe

3. Update for Windows XP x64 Edition (KB961118)
Size=872312
Date=Tue Feb 24 00:00:00 2009
Priority=2
Delta=0
Beta=0
Action=1
ID=72ae05ee-6290-4e4c-a8f9-ecfa416b067c
Download URL(s):
http://download.windowsupdate.com/msdownload/update/software/crup/2009/02/windowsserver2003.windowsxp-kb961118-x64-enu_dcb0eef40327825d619ed19338a9a68fe69bb6fe.exe

4. Microsoft .NET Framework 3.5 SP1 and .NET Framework 2.0 SP2 Update for Windows Server 2003 and Windows XP for x64-based Systems (KB982524)
Size=31680584
Date=Tue Jul 27 00:00:00 2010
Priority=1
Delta=0
Beta=0
Action=1
ID=fd730688-8e7a-41ce-93f2-3450c5b3832f
Download URL(s):
http://download.windowsupdate.com/msdownload/update/software/secu/2010/05/msipatchregfix-x64_dd729362b73e94700b3eeec77fd581bd767b47e1.exe
http://download.windowsupdate.com/msdownload/update/software/updt/2010/02/ndp20sp2-kb976576-x64_29d95e9cee9cf2e838a3e1fe8d6216cc2799550b.exe
http://download.windowsupdate.com/msdownload/update/software/crup/2010/06/ndp30sp2-kb977354-v2-x64_f19f9ebce70fc004c33be93e5c595925f4f05899.exe

5. Microsoft .NET Framework 4 Client Profile for Windows XP x64-based Systems (KB982670)
Size=45071024
Date=Tue Sep 13 00:00:00 2011
Priority=1
Delta=0
Beta=0
Action=1
ID=434aa8fa-b425-47a9-be5b-dd000b66c6ed
Download URL(s):
http://download.windowsupdate.com/msdownload/update/software/ftpk/2011/08/dotnetfx40_client_x86_x64_a96cef357b16f0dea3423bf6c515a96a3c2233de.exe

6. Security Update for Microsoft .NET Framework 2.0 SP2 on Windows Server 2003 and Windows XP for x64-based Systems (KB2729450)
Size=31454256
Date=Tue Nov 13 00:00:00 2012
Priority=2
Delta=0
Beta=0
Action=1
ID=cee83adc-d8d7-43d0-905b-6351e3341822
Superseded ID(s):
2b4df0db-ada4-4ae4-86ef-6634d0cd3219
6894a994-d6fc-4f15-8142-83d79c84eff0
ae04de58-8ea0-47a9-a49a-0ac80ba2835b
aee1e679-770b-40ef-9701-02ed03f78468
Download URL(s):
http://download.windowsupdate.com/msdownload/update/software/secu/2012/10/msipatchregfix-amd64_5011cb29b096fb674a4795ee8fc2f7fdad33863a.exe
http://download.windowsupdate.com/msdownload/update/software/secu/2012/10/ndp20sp2-kb2729450-x64_26a72f0f0db6ebac5aede881c56102b3cf250928.exe

Share this post


Link to post
Share on other sites
TuMaGoNx    48

SFX now prioritize batch file of same filename, useful for mass wrapper
for ex.
put several batch files into sfx
renaming sfx.exe as myprogram.exe will try execute myprogram.bat/cmd if exists, similar to busybox

SFX now fallback to system cmd if roscmd not present
all executables now should reside in bin subdir which prepended into PATH


download
https://github.com/tumagonx/portabat/raw/master/basebin/7z.sfx
https://github.com/tumagonx/portabat/raw/master/basebin/roscmd.exe

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×