Presentation is loading. Please wait.

Presentation is loading. Please wait.

Executing Host Commands

Similar presentations


Presentation on theme: "Executing Host Commands"— Presentation transcript:

1 Executing Host Commands
MIS 3406 Department of MIS Fox School of Business Temple University

2 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

3 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

4 Execute a command at the command line…
Arguments 1, 2 and 3 stdout

5 Let’s execute it within NodeJS…
Setup .spawnSync stdout Command Arguments 1, 2 and 3 stderr Exit Code

6 How about a bad command…
Setup .spawnSync stdout Command Arguments 1, 2 and 3 stderr Exit Code

7 OS Command (not a .exe) Command Arguments Need a Shell stdout stderr
Exit Code

8 HostCommandWithExe.js Get your first program running that executes a host command with an exe.

9 HostCommandWithoutExe.js Get your first program running that executes a host command without an exe.

10 MyPing.js Write a script that is passed the name of a node to ping which then pings that node, captures the output. If the Exit Code is 0 displays the message “The node is reachable” and just the “Reply” line from stdout. If the Exit Code is 1 the script displays the message “The node is not reachable”.

11 MyDir.js Write a script that uses the “DIR” command to show all of the files with an extension of “.js” in the current directory and captures the output. Display just the file names of each “.js” file in the directory.

12 WhoAmI.js Write a script that executes the “set” command and captures the output. Display the user that is currently logged on by finding and parsing the “USERNAME=“ string in the output.

13 MyHostName.js Write a script that executes the hostname command and captures the output. Display the string, “The name of my computer is hostname” where hostname contains the name that was returned by the hostname command

14 MyIPAddress.js Write a script that executes the “IPCONFIG /ALL” command and captures the output. Display the string, “My IP address is xxx.xxx.xxx.xxx” where “xxx.xxx.xxx.xxx” is the IP address returned from the “IPCONFIG /ALL” command.

15 LookuoIPAddress.js Write a script that is passed the name of a server or website like and uses the nslookup command to look up the IP address of this server or website. Display the IP address of this server or website so it looks like: The IP address of is


Download ppt "Executing Host Commands"

Similar presentations


Ads by Google