Previous Topic: Remote Batch ModeNext Topic: Writing Data to the Console (stdout)


Stringification

Stringification takes a sequence of characters and turns it into a JavaScript literal string. For example, the AutoShell get-help command that takes a filter string as an optional parameter:

get-help help

Because AutoShell uses an out-of-the-box JavaScript interpreter, any command entered at the prompt or in a script file, is translated into valid JavaScript syntax. The AutoShell command translation layer turns the command into a JavaScript function call:

help( "help" );

Literal strings in JavaScript must always be enclosed in quotes, therefore the command translation layer automatically places quotes around the string specified in the command. If quotes are found around a string, it is not stringified again.

Special characters inside literal JavaScript strings must be escaped. In particular, backslash and quotes inside quote delimited strings. Escaping is done by prefixing these special characters with a backslash. Consider the AutoShell dir command (1) that gets translated to a function call (2):

(1) dir c:\Program Files\CA\*.*
(2) ca.aip.direct.directory("c:\\Program Files\\CA\\*.*" ,"",false,false, false, false);

Quotes may be required when dealing with strings that contain spaces and take multiple input parameters in one option. If a string with spaces inside is specified without quotes, the space is interpreted as an argument delimiter until all input parameters a matched. To prevent this behavior use quotes.

Instead of using a command without quotes (1), escape backslashes, and enclose the path in quotes so that AutoShell correctly identifies arguments (2):

(1) copy c:\Program Files\CA\*.* c:\temp
(2) copy "c:\\Program Files\\CA\\*.*" c:\temp

Note: Because the command translation layer does not stringify the path, special characters inside the string must be escaped manually.

To keep a string including spaces together and still get automatic escaping of special characters, you can also use the _S() macro:

copy _S(c:\Program Files\CA\*.*) c:\temp

When using AutoShell commands to automate tasks, parts of the commands must often accept input from JavaScript variables. In this case, prevent stringification. Otherwise, the variable name is turned into a literal string and the command does not produce the expected result. To prevent stringification of an expression, place the expression into parenthesis:

var topic = "help";
get-help (topic)