Search found 135 matches

by Eureka!
27 Aug 2019 14:13
Forum: DOS Batch Forum
Topic: "bat" file keeps closing after executing
Replies: 5
Views: 7721

Re: "bat" file keeps closing after executing

For some reason after I "right click" and "run as Administrator" Be aware that if you start your script like that, you will end up with a completely different %USERNAME% if you weren't logged in as a local administrator. My advice: Split your script in a SYTEM part and a USER part. (although there ...
by Eureka!
11 Aug 2019 08:50
Forum: DOS Batch Forum
Topic: SORT Order not working correction
Replies: 8
Views: 11860

Re: SORT Order not working correction

And yet another way: If you have cygwin or Linux Subsystem for Windows (*) installed, you can do: c:\Tools\cygwin64\bin\sort --field-separator "|" +4 --numeric-sort filename.txt or short: sort -t "|" +4 -n sort filename.txt (sort by field 4 (first=0) ; use natural sort) (*) or whatever it is called ...
by Eureka!
11 Aug 2019 08:34
Forum: DOS Batch Forum
Topic: Problem with random number generator
Replies: 3
Views: 6466

Re: Problem with random number generator

if %max% % 1 neq 0 (goto InvalidMaximumIsNotAnInteger) If you want to do calculations in batch, use set /A ... set /a TEST=%max% %% 1 if %TEST% neq 0 (goto :InvalidMaximumIsNotAnInteger) Further: you need to rethink this code: set /a result=(%RANDOM%*%max%/32768)+%min% For example, if min=1000, max...
by Eureka!
11 Aug 2019 08:24
Forum: DOS Batch Forum
Topic: String manipulation - remove leading and trailing spaces
Replies: 2
Views: 8694

Re: String manipulation - remove leading and trailing spaces

Welcome to the forum! :) Thanks! ... a general-purpose solution ... I never had the illusion that this was a universal solution. Most times you know what format/layout the output will be. And if suitable, this is a short, straightforward fix. (But hadn't thought about %'s and /'s) Impenetrable spag...
by Eureka!
11 Aug 2019 08:10
Forum: DOS Batch Forum
Topic: Problem with "start" command
Replies: 5
Views: 9212

Re: Problem with "start" command

specify a path to the logfile, so you are not depending on the current working directory.
For example if you run elevated, the default cwd is c:\windows'system32.


set LOGFILE=%~dp0log.txt
....
@echo [%time%] [Command] "%choice%" >> "%LOGFILE%"
by Eureka!
11 Aug 2019 07:55
Forum: DOS Batch Forum
Topic: Trying to build a Uptime.exe alternative via native windows
Replies: 31
Views: 33523

Re: Trying to build a Uptime.exe alternative via native windows

Not all systems have powershell by default. You are right. I subtitled "remote machines" in my head as servers, but that isn't necessarily the case (servers without PowerShell are very hard to come by) A batch syntax is simpler and more familiar to most people. The batch scripting is funnier than p...
by Eureka!
07 Aug 2019 09:02
Forum: DOS Batch Forum
Topic: Trying to build a Uptime.exe alternative via native windows
Replies: 31
Views: 33523

Re: Trying to build a Uptime.exe alternative via native windows

Why would anyone try to accomplish this in CMD these days, when there is PowerShell? A hybrid soultion: @echo off setlocal echo. Start = %TIME% for /f "usebackq tokens=1,* delims=: " %%x in (`powershell.exe -nologo -noprofile -executionpolicy bypass "(get-date) - (Get-CimInstance Win32_OperatingSyst...
by Eureka!
05 Aug 2019 13:51
Forum: DOS Batch Forum
Topic: String manipulation - remove leading and trailing spaces
Replies: 2
Views: 8694

String manipulation - remove leading and trailing spaces

Just reading the String Manipulation page . There is another way - beside the ones mentioned on that page - to remove leading and trailing spaces: set str= 15 Leading and Trailing Spaces to truncate &rem echo."%str%" for /f "tokens=*" %%A in ("%str%") do set str=%%~pnxA set str=%str:~1% echo."%str%"...
by Eureka!
03 Aug 2019 10:22
Forum: DOS Batch Forum
Topic: SUDO for CMD
Replies: 9
Views: 17384

Re: Run elevated commands / programs / shell

Thank you for your feedback :thumbsup:
(I started to think the forum went dead ..)
by Eureka!
03 Aug 2019 10:20
Forum: DOS Batch Forum
Topic: Combine CSV Files
Replies: 3
Views: 6154

Re: Combine CSV Files

sort /unique :shock: Thank you!! I was using a 3rd party SORT especially for that. Thanks for mentioning that undocumented feature. Yet another way (of the many) to approach this: @echo off setlocal enabledelayedexpansion for %%x in (*-*.csv) do ( set COMBI=%%x if not exist "!COMBI:~0,2!.csv" copy ...
by Eureka!
31 Jul 2019 04:44
Forum: DOS Batch Forum
Topic: Combine CSV Files
Replies: 3
Views: 6154

Re: Combine CSV Files

If your CSV files are rather small ( couple of hundred lines each), this should do it:

Code: Select all

@setlocal
@for %%x in (*-*.csv) DO @(set COMBI=%%x & call type %%x >>%COMBI:~0,2%.csv)
For larger files, the copy syntax copy fileA + fileB is probably faster.
by Eureka!
29 Jul 2019 09:21
Forum: DOS Batch Forum
Topic: Is it possible to pull variable out of setlocal and endlocal pair in for loop
Replies: 1
Views: 4151

Re: Is it possible to pull variable out of setlocal and endlocal pair in for loop

Assuming this is an XY-problem: Easiest way that I know is replacing the for ... DO ( <lots of commands> ) with: for ... DO call :label . That will even get rid of the setlocal/endlocal pair. I didn't understand what you were trying to accomplish, but this should give you some inspiration: @echo off...
by Eureka!
28 Jul 2019 13:15
Forum: DOS Batch Forum
Topic: SUDO for CMD
Replies: 9
Views: 17384

SUDO for CMD

Just discovered this forum a couple of days ago and I have to say that it contains a wealth on information and groundwork research on batch mechanics. Very interesting! One of the things I noticed is the hybrid VBSsript - batch approach used in several threads to run commands elevated. Here is a pur...
by Eureka!
27 Jul 2019 15:53
Forum: DOS Batch Forum
Topic: Animated loading screen
Replies: 8
Views: 19149

Re: Animated loading screen

bt.player wrote:
26 Jul 2019 14:08
You can using this.
[...]
Thank you !!
Very elegant (and looking deceivingly simple ...)