A powerful Node.js command executor with real-time output streaming and process management capabilities. Perfect for running system commands, managing long-running processes, and handling real-time command outputs.
.---. .-. .-..----. .----..-. .-..----..---. .-. .-. .---. .-. .----. .-. .-..----..----.
/ ___}| `.' || {} \ | {_ \ \/ / | {_ / ___}| { } |{_ _}| |/ {} \| `| || {_ | {} }
\ }| |\ /| || / | {__ / /\ \ | {__\ }| {_} | | | | |\ /| |\ || {__ | .-. \
`---' `-' ` `-'`----' `----'`-' `-'`----'`---' `-----' `-' `-' `----' `-' `-'`----'`-' `-'
- Real-time command output streaming
- Process management and control
- Built-in timeout handling
- Error and warning event emission
- Memory-efficient stream processing
- Support for one-time and long-running commands
- Built-in help system
npm install cmd-realtime-executioner
const { CommandExecutor } = require('cmd-realtime-executioner');
async function runCommand() {
const executor = new CommandExecutor();
try {
const output = await executor.execute('dir');
console.log(output);
} catch (error) {
console.error('Command failed:', error);
}
}
const executor = new CommandExecutor();
const process = await executor.realtimeExecution(
'ping',
['google.com'],
{ timeout: 5000 },
(data, type) => {
if (type === 'stdout') {
console.log('Output:', data);
}
}
);
// Stop a specific process
await process.stop();
// Check if process is running
const isRunning = process.isRunning();
// Stop all processes
await executor.stopAll();
const executor = new CommandExecutor();
executor.on('error', (error) => console.error('Error:', error));
executor.on('warning', (warning) => console.warn('Warning:', warning));
The package includes examples for integrating with TShark for network packet capture:
const { capturePackets, listInterfaces } = require('./tshark.js');
// List available interfaces
await listInterfaces();
// Start packet capture
await capturePackets();
const capture = await executor.realtimeExecution(
'"C:\\Program Files\\Wireshark\\tshark"',
[
'-i', '5', // Interface number
'-T', 'fields', // Output format
'-E', 'header=y', // Include headers
'-e', 'frame.time', // Timestamp
'-e', 'ip.src', // Source IP
'-e', 'ip.dst', // Destination IP
'-e', 'ip.proto' // Protocol
],
{ timeout: 0 },
async (data, type) => {
console.log('Packet:', data.trim());
}
);
execute(command, options)
: Execute a one-time commandrealtimeExecution(command, args, options, onData)
: Execute a command with real-time outputstopProcess(processId)
: Stop a specific processisProcessRunning(processId)
: Check process statusstopAll()
: Stop all running processes
const defaultOptions = {
encoding: 'utf8',
shell: true,
maxBuffer: 1024 * 1024 * 100,
timeout: 0 // 0 means no timeout
};
Access built-in help documentation:
node your-script.js --help # Basic help
node your-script.js -h --detailed # Detailed help
const executor = new CommandExecutor();
const output = await executor.execute('dir');
const capture = await executor.realtimeExecution(
'ping',
['google.com', '-t'],
{ timeout: 10000 },
(data) => console.log(data)
);
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
ISC