NAME

run_subprocess.pl - Script to run sub processes in an easy post-processable way

DESCRIPTION

run_subprocess.pl captures the STDOUT, STDERR, the EXIT CODE from a sub process and parses it into JSON, YAML or Plain Text formats.

OVERVIEW

run_subprocess.pl [-bcdfhnrtx] [long options...]
  -c STR --command STR      the COMMAND to be run
  -n STR --name STR         the NAME for the COMMAND
  -r INT --readtimeout INT  the TIMEOUT for reading of the output from
			                            COMMAND
  -t INT --timeout INT      the TIMEOUT for execution the COMMAND
  -x --exit                 execution returns exit code
  -f STR --format STR       the format for the output
  -b STR --boundary STR     boundary string for the plain text output
  -d --debug                execution debug output
  -h --help                 print usage message and exit

See Method Process::SubProcess::setArrProcess()

EXAMPLES

Plain Test Format with Boundary
$ bin/run_subprocess.pl -n "test-script fails" -c "t/test_script.pl 3 6" -b ':====' -t 2

script 'run_subprocess.pl' - Command Result:
:====SUMMARY:
command: t/test_script.pl 3 6
name: test-script fails
pid: 7387
exit code: -1
error code: 4
:====STDOUT:
:====STDERR:
script 'test_script.pl' START 0 ERROR
Sub Process (7387) 'test-script fails': Execution timed out!
Execution Time '2 / 2'
Process will be terminated.
Sub Process (7387) 'test-script fails': Process terminating ...
:====END:====
JSON Format
$ bin/run_subprocess.pl -n "test-script" -c "t/test_script.pl 2 0" -f json | jq '.'

{
  "exit_code": 0,
  "error_code": 0,
  "name": "test-script",
  "command": "t/test_script.pl 2 0",
  "stdout": "Start - Time Now: '1688649512.50548' s\nscript 'test_script.pl' START 0\nscript 'test_script.pl' PAUSE '2' ...\nscript 'test_script.pl' END 1\nEnd - Time Now: '1688649514.50564' s\nscript 'test_script.pl' done in '2000.16093254089' ms\nscript 'test_script.pl' EXIT '0'\n",
  "pid": "14911",
  "stderr": "script 'test_script.pl' START 0 ERROR\nscript 'test_script.pl' END 1 ERROR\n"
}
YAML Format
$ bin/run_subprocess.pl -n "test-script" -c "t/test_script.pl 2 0" -f yaml

---
command: t/test_script.pl 2 0
error_code: 0
exit_code: 0
name: test-script
pid: 14928
stderr: |
  script 'test_script.pl' START 0 ERROR
  script 'test_script.pl' END 1 ERROR
stdout: |
  Start - Time Now: '1688649560.87845' s
  script 'test_script.pl' START 0
  script 'test_script.pl' PAUSE '2' ...
  script 'test_script.pl' END 1
  End - Time Now: '1688649562.8786' s
  script 'test_script.pl' done in '2000.1528263092' ms
  script 'test_script.pl' EXIT '0'
JSON Format extracting STDOUT and EXIT CODE
$ bin/run_subprocess.pl -n "test-script" -c "t/test_script.pl 2 0" -f json | jq '.stdout,.exit_code'

"Start - Time Now: '1688649702.23336' s\nscript 'test_script.pl' START 0\nscript 'test_script.pl' PAUSE '2' ...\nscript 'test_script.pl' END 1\nEnd - Time Now: '1688649704.23352' s\nscript 'test_script.pl' done in '2000.15997886658' ms\nscript 'test_script.pl' EXIT '0'\n"
0