How can I “intercept” Ctrl+C in a CLI application?

Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { /* my shutdown code here */ } }); This should be able to intercept the signal, but only as an intermediate step before the JVM completely shutdowns itself, so it may not be what you are looking after. You need to use a SignalHandler (sun.misc.SignalHandler) to intercept the … Read more

Does PHP have threading?

From the PHP manual for the pthreads extension: pthreads is an Object Orientated API that allows user-land multi-threading in PHP. It includes all the tools you need to create multi-threaded applications targeted at the Web or the Console. PHP applications can create, read, write, execute and synchronize with Threads, Workers and Stackables. As unbelievable as … Read more

Execute a command line binary with Node.js

For even newer version of Node.js (v8.1.4), the events and calls are similar or identical to older versions, but it’s encouraged to use the standard newer language features. Examples: For buffered, non-stream formatted output (you get it all at once), use child_process.exec: const { exec } = require(‘child_process’); exec(‘cat *.js bad_file | wc -l’, (err, … Read more

How to delete subfolders and Files but not parent Folder in windows using Script? [closed]

As PowerShell supports wildcards/patterns on multiple levels of a path, it’s as simple as: Get-ChildItem D:\test[1-3]\* | Remove-Item -Recurse -Force Sample tree before and after running the command: > tree /F D:. ├───test1 │ └───test1 │ └───archive │ x.txt │ ├───test2 │ └───try │ └───archive │ x.txt │ └───test3 └───model └───archive x.txt > Get-ChildItem D:\test[1-3]\*|Remove-Item … Read more