Log in to check your private messagesLog in to check your private messages   Log inLog in 

 
Script to Run an Executable and its Parse Output

 
Post new topic   Reply to topic    Tembria Forums Forum Index : Script Library and Discussions
View previous topic :: View next topic  
Author Message

Tembria Support



Joined: 26 Aug 2005
Posts: 398

PostPosted: Mon Dec 05, 2005 3:20 pm    Post subject: Script to Run an Executable and its Parse Output Reply with quote

The following script can be used with Tembria Server Monitor's JScript event monitor.

It shows all of the elements necessary to run a command line program, parse its output and then warn based upon what it finds.

Code:

// declare variables
var shell,fso,file,txt;

// create objects that we'll need
shell = new ActiveXObject( "WScript.shell" );
fso = new ActiveXObject("Scripting.FileSystemObject");

// run the program
shell.Run("cmd /c echo abc > test.txt", 1, true);

// parse the results
file = fso.OpenTextFile("test.txt", 1);
txt = file.ReadAll();
file.close();

// report results
if (txt.indexOf("abc")!=-1)
{
  WScript.Echo("Result=Success");
  WScript.Echo("LogText=The file contains 'abc'.");
}
else
{
  WScript.Echo("Result=Error");
  WScript.Echo("LogText=The file does not contain 'abc'.");
}



Just replace the command "echo abc" with the full path to the executable to run and change 'abc' to the text you want to look for in the output. Lastly, modify the LogText returned as you see fit.

Tembria Support
support@tembria.com
Back to top
View user's profile Send private message Visit poster's website

kevin



Joined: 06 Jan 2010
Posts: 2

PostPosted: Thu Jan 07, 2010 9:34 pm    Post subject: how to test this? Reply with quote

Can you please also provide the details on how to test this script from the machine and if the script should be saved under certain extension to be executed properly?

Can I save the script as a txt file?

How do I execute it from CMD?

If there are quotation marks in the command, what do i do? just use it twice?

Thanks for your help.
Back to top
View user's profile Send private message

Tembria Support



Joined: 26 Aug 2005
Posts: 398

PostPosted: Mon Jan 18, 2010 12:17 pm    Post subject: Reply with quote

Hi Kevin,

Quote:
Can you please also provide the details on how to test this script from the machine and if the script should be saved under certain extension to be executed properly?


To test the script you can run from the command line:

Code:
cscript myscript.ext


The extension must match the language of the script you are developing, for example ".vbs" for VBScript and ".js" for JScript.

Quote:
Can I save the script as a txt file?


For testing purposes you can, and use the cscript option to specify the language directly, but for use from within Tembria Server Monitor, it needs to have the extension that matches the scripting language.

Quote:
If there are quotation marks in the command, what do i do? just use it twice?


It is different for each scripting language. In VBScript you use two doublequote characters . JScript you can put a backslash character in front of the quote character as in \"

Tembria Support
support@tembria.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Tembria Forums Forum Index : Script Library and Discussions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum