The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,312 other followers

Archive for the ‘Batch-Files’ Category

Windows/*n*x: Getting curl to output HTTP status code – Super User

Posted by jpluimers on 2017/10/24

The first trick works in Windowa and nx (thanks [WayBackpvandenberk):

curl -s -o /dev/null -I -w "%{http_code}" http://www.example.org/

Inside a Windows batch file you need to escape the % to %% so you get this:

curl -s -o /dev/null -I -w "%%{http_code}" http://www.example.org/

The second is slick but only works on nx (thanks [WayBackHeath Borders):

#creates a new file descriptor 3 that redirects to 1 (STDOUT)
exec 3>&1
# Run curl in a separate command, capturing output of -w "%{http_code}" into HTTP_STATUS
# and sending the content to this command's STDOUT with -o >(cat >&3)
HTTP_STATUS=$(curl -w "%{http_code}" -o >(cat >&3) 'http://example.com')

[WayBackGetting curl to output HTTP status code? – Super User

–jeroen

Posted in *nix, *nix-tools, bash, Batch-Files, cURL, Development, Power User, Scripting, Software Development | Leave a Comment »

For – Loop through a range of numbers | Windows CMD | SS64.com

Posted by jpluimers on 2017/06/27

Since I always forget:

for /l %1 in (1,2,200) do echo %1 >> text-%1.txt

This creates files with incremental filenames like this:

text-1.txt
text-3.txt
...
text-199.txt

–jeroen

via: For – Loop through a range of numbers | Windows CMD | SS64.com [WayBack]

Posted in Batch-Files, Development, Scripting, Software Development | 4 Comments »

How bad is the Windows command line really?

Posted by jpluimers on 2017/04/13

How bad is the Windows command line really?

The Windows command line is bad. Very bad.

But it took until recently for old Windows versions – that out of the box had either no or poor PowerShell versions – to have slowly died.

So only now PowerShell finally has become an option that really works across all Windows versions I use. Go PowerShell!

–jeroen

Posted in Batch-Files, Development, PowerShell, Scripting, Software Development | Leave a Comment »

7zip: compress from the command-line; a few notes and a small batch file

Posted by jpluimers on 2017/04/04

I wanted to compress a few files from the current directory in a zip file using the 7z.exe command-line version of 7zip.

The trick is about finding where 7z.exe is as the directory containing 7z.exe is not in the Windows PATH.

Notes:

setlocal
call SortDateTime.bat
echo %SortDateTime% %SortDate%-%SortTime%

for /f "usebackq tokens=2* delims= " %%c in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip" /v Path`) do (
  set sevenzExe="%%d7z.exe"
)
endlocal & if exist %sevenzExe% %sevenzExe% a -tzip _my-build.%SortDate%-%SortTime%.zip MyServer.exe MyServer.map MyClient.exe MyClient.map

pause

–jeroen

Posted in Batch-Files, Development, Power User, Scripting, Software Development | Leave a Comment »

defrag.exe: tracking an already in progress operation can be done from non-admin session

Posted by jpluimers on 2017/03/17

When you want to defrag.exe (the built-in Windows one, not the SysInternals Windows NT4 one, so make sure SysInternals comes last in your path) a volume, you have to run it with an elevated UAC Admin token.

But I just found out that you can do this without an Admin token:

C:\Windows\System32>Defrag.exe C: /t /v /u
Microsoft Drive Optimizer
Copyright (c) 2013 Microsoft Corp.

Tracking operation on (C:)...


Performing pass 2:
        Free Space Consolidation:  31% complete...

This makes it much easier to separate monitoring scripting from execution.

–jeroen

Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »

 
%d bloggers like this: