Aacini wrote:- The "if defined %%?" part in your code is not needed because the "set" command list defined variables only. Perhaps whitout the "if", the clean memory process run faster.
Not quite;
Code: Select all
@echo off &setlocal enableDelayedExpansion &set $lf=^
::need line
set "$=echo.hi!$lf! =notDefined"
for /F "tokens=1 delims==" %%? in ( 'set $' ) do echo.set "%%?=" &set "%%?="
pause
exit
Code: Select all
set "$="
set " ="
De syntaxis van de opdracht is onjuist.
set "$lf="
Druk op een toets om door te gaan. . .
Now I need to redirect stream2 to nul, which explains the presence of the if statement. Though redirecting stream2 to nul and leaving out 'if' is probably faster.
Aacini wrote:- Run the clean memory process this way; it should run faster:
Code: Select all
for /F "tokens=1 delims==" %%? in (
'set ^| sort /R'
) do set "%%?="
It does avoid the 'De syntaxis van de opdracht is onjuist.' error thrown by set, but why sorting the variables before processing them by for would be faster ?
Aacini wrote:- You said "actual memory is only 5MB", but the test batchfile fills it up to 250MB. If the "actual memory" is complete before the develop and test part begins, you may execute a "setlocal" command at that point. This way, if you execute an "endlocal" before start the new instance of CMD, all the additional memory taken from the test part will be released.
The parent process uses 250MB and so does the child when it is spawned, ( if left uncleaned, even if it really only uses about 5MB, that tells me reserved memory is also copied even if unset. this particular test does not uses a significant amount of memory, but at this point the batchfile does since this test is near the end of the batchfile and by now pretty much all macro's have been defined. The 250MB cannot be endlocalled because the parent is in global environment so it can pass it's environment to it's caller batch when it ends.
Aacini wrote:- Your "secret switch" is "start"'s command /I switch. Try to start the new instance of CMD this way:
Code: Select all
START /I CMD.EXE same switches and parameters...
Antonio
Ok that helps, but what /I actually does is return me the DOS environment of the batch that started a batch that called this batch that starts this new instance.
Code: Select all
aBatchFile:start "bBatchFile" // this environment is returned when using the /I switch on next start command
bBatchFile:call "cBatchFile"
cBatchFile:start /I "dCommand"
Didn't know you could create a process with WMIC that uses the default environment, it's much more elegant and efficient way to default back to original environment.
aGerman wrote:Well, at least no direct child processes.
To work around it you could use a scheduled task that you could call via SCHTASKS /RUN.
Also WMIC could help. E.g.
Code: Select all
@echo off &setlocal
if "%~1"=="test" (
set xyz
pause
exit /b
)
set "xyz=Hello!"
set xyz
>nul wmic process call create "cmd /c %~fs0 test"
pause
cool, I will see if I can use this for cmdContext macro's with delayed linefeeds in it, I fear for it though..
The thing is that in a cmdLineContext a linefeed has to be entered like this
Code: Select all
set "$cmd=echo.hello%%$lf%%echo.there"
cmd /C "!$cmd!"
So the linefeed is expanded after the new instance has spawned, this is the only variable that should NOT be undefined. Now I'd have to edit the registry to see if I can make it part of the default environment. ugh
I probably better just convert my variable so it won't contain any linefeeds in the first place.
Thanx aGerman