Executing Host Commands MIS 3406 Department of MIS Fox School of Business Temple University
Why Execute Host Commands Why would you want to execute host commands within code? Automate repetitive tasks Moving data Monitoring systems Backups DevOps Automated operations Automated testing Automated migration of code and data Dev QA Prod
What do you need to be able to do? Execute a command Capture and process the output Stdout – Stderr – Capture the “Exit Code” (a.k.a. “Return Code”) Conditional execution of code based on results of the host command
Execute a command at the command line… Arguments 1, 2 and 3 stdout
Let’s execute it within NodeJS… Setup .spawnSync stdout Command Arguments 1, 2 and 3 stderr Exit Code
How about a bad command… Setup .spawnSync stdout Command Arguments 1, 2 and 3 stderr Exit Code
OS Command (not a .exe) – Windows Only Arguments Need a Shell stdout stderr Exit Code
HostCommandWithExe.js Get your first program running that executes a host command with an exe.
HostCommandWithoutExe.js Get your first program running that executes a host command without an exe.
Challenges MyPing MyDir WhoAmI MyHostName MyIPAddress LookupIPAddress