Skip to content

Command executor#36

Merged
salazarsebas merged 5 commits intoScaffoldRust:mainfrom
Benjtalkshow:command-executor
Aug 9, 2025
Merged

Command executor#36
salazarsebas merged 5 commits intoScaffoldRust:mainfrom
Benjtalkshow:command-executor

Conversation

@Benjtalkshow
Copy link
Contributor

Closes #25

Secure Shell Command Executor Utility

Description

This task adds a safe way to run shell commands in Node.js with built-in timeout and error handling.
It uses child_process.spawn to avoid command injection risks and allows you to set how long a command can run.

Changes

  • Added commandExecutor.ts utility file.
  • Created executeCommand() function that:
    • Runs commands securely with spawn.
    • Has a timeout option (default: 30 seconds).
    • Handles errors clearly.
    • Keeps stdout and stderr separate.
  • Added command-executor.ts test script with:
    • Success tests.
    • Error tests.
    • Timeout tests.
    • Works on macOS and Linux.

Technical Details

  • Uses spawn instead of exec for better security.
  • Written in TypeScript with type checking.
  • Checks inputs before running.
  • Returns clear error details (stderr, exit code).
  • Tested with:
    • Simple commands (echo, ls).
    • Command chains (&&).
    • Error cases.
    • Timeout situations.

Testing

Run the tests:

bun run command-executor
bun run command-executor "echo hello"
bun run command-executor "ls non-existent-file"
bun run command-executor "ping -c 5 localhost" -t 1000

@Benjtalkshow
Copy link
Contributor Author

@salazarsebas
Kindly view

Copy link
Member

@salazarsebas salazarsebas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@salazarsebas salazarsebas merged commit 8aec297 into ScaffoldRust:main Aug 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create commandExecutor for Secure Shell Commands [backend]

2 participants