Skip to content

Instantly share code, notes, and snippets.

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.InvalidOperationException: StandardIn has not been redirected.
at System.Diagnostics.Process.get_StandardInput()
at ShareX.HelpersLib.ExternalCLIManager.WriteInput(String input)
at ShareX.ScreenRecordForm.StopRecording()
at ShareX.ScreenRegionForm.OnStopRequested()
at ShareX.ScreenRegionForm.btnAbort_MouseClick(Object sender, MouseEventArgs e)
@davidruhmann
davidruhmann / Example_Line.bat
Created December 4, 2012 21:07
[Batch] Get the line number of a statement within a batch file. (Debugging)
:: Batch Code Line Debugging
:: Retrieve the batch file line number where the Line function is called.
:: by David Ruhmann
:: Hide Command and Isolate Scope
@echo off
setlocal
:: Usage Example
call :False xResult
@davidruhmann
davidruhmann / Example_Parse.bat
Last active October 13, 2015 16:48
[Batch] Parse the command line parameters for easy consumption
:: Parse Example
:: Set a variable for each parameter flag to the value. flag:value, xflag=value
:: by David Ruhmann
:: Hide Commands
@echo off
:: Initilize Example
set "xParams=%*"
echo.%*
@davidruhmann
davidruhmann / Log.bat
Created December 6, 2012 22:49
[Batch] Log a message to a file and or the screen
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Log <xLog> <xMessage> [xParrot] [xSession]
:: Append the message with a timestamp out to the specified log file and repeat
:: the message to the display if xParrot is set to 1.
if not "%~1"=="" if exist "%~1" echo.%Date% %Time% %~4: %~2 >> "%~1"
if /i "%~3"=="1" echo.%~2
goto :eof
:: by David Ruhmann
@davidruhmann
davidruhmann / IsDecimal.bat
Created December 6, 2012 23:47
[Batch] Numeric validation methods.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:IsDecimal <xReturn> <xInput> [xDelims]
:: Return true if the input is a decimal 10.0 number, else return false.
:::: Only allows for period seperator unless specified by xDelims. ,[tab][space]
call :IsNumber %1 %2 %3
goto :eof
:: by David Ruhmann
@davidruhmann
davidruhmann / Example_IsDefined.bat
Created December 7, 2012 17:00
[Batch] Detect if a variable name is defined with a value.
:: Determine if a Variable name is defined with a value.
:: by David Ruhmann
:: Hide Commands
@echo off
setlocal ENABLEEXTENSIONS
:: Example Usage
set "xVar=Value"
call :IsDefined xResult xVar
@davidruhmann
davidruhmann / ReplaceWith.bat
Created December 8, 2012 01:59
[Batch] Replace a line in a file containing the term with the entire contents of the input file.
:: Hide Command
@echo off
set "xResult="
::if exist "Output.xml" del /f /q "Output.xml"
call :ReplaceWith xResult "Source.xml" "<Tools>" "Input.xml" "Output.xml"
echo.%xResult%
goto End
setlocal
set "myString=abcdef!%%^^()^!"
call :strlen result myString
echo %result%
goto :eof
:strlen <resultVar> <stringVar>
(
setlocal EnableDelayedExpansion
set "s=!%~2!#"
@davidruhmann
davidruhmann / SingleChar.bat
Created December 20, 2012 19:05
[Batch] Output Single Char
:: Output a single character.
:: Does not work with whitespace on versions of Windows
:: after XP which trim leading whitespace.
>File.txt ( <nul set /p "= " )
:: Output 0x0C New Page
cls>File.txt
@davidruhmann
davidruhmann / RoboCopyDelete.bat
Last active December 10, 2015 07:38
[Batch] Delete files younger than 5 days old with RoboCopy
:: Create an empty temp directory and purge all files and folders in the current directory that are younger than 5 days old.
:: See RoboCopy /? for all of the available options like /E for recursive. Remove /L to actually perform the deletions.
RD /S /Q "%Temp%\Temp" 2>nul & MKDIR "%Temp%\Temp" && ROBOCOPY "%Temp%\Temp" "C:\Backup" /PURGE /MT /MAXAGE:5 /NS /NC /NJH /NJS /L