Previous Topic: Reading Data from the Keyboard (stdin)Next Topic: Using the OSRedirect Class


Accessing the Operating System

Management shells often call operating system commands or other native utilities to accomplish system-related tasks. From the interactive AutoShell prompt or from within scripts, execute OS commands by prefixing them with an exclamation mark. The exclamation mark must always be the first non-whitespace character of the input line.

By default, AutoShell writes the output of OS commands directly to the AutoShell console. However, output that is written to the AutoShell console is not directly accessible by AutoShell for further processing. Applications that process child process output typically redirect the output to a file and read that file after the child process terminates. AutoShell lets you directly assign child process output to a JavaScript object. See the following examples.

You can launch any application from AutoShell using the OS access. When invoking OS commands, AutoShell always waits for the command to complete before returning to the command prompt or continuing script execution.

Examples

List the files in the current directory, print the version of the running OS, and start Notepad. These sample commands run without any AutoShell interaction. The first of the following commands uses the operating system dir command but not the built-in Autoshell dir command. AutoShell waits until the Notepad application is closed.

! dir
! ver
! notepad

Concatenate commands by using an ampersand "&" and execute them with a single child process:

! dir >t.txt & type t.txt