Check File Content

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
Malus
Posts: 1
Joined: Fri Mar 18, 2016 9:13 am

Check File Content

Post by Malus »

Hello Guys,

i want to check the content of a textfile.
Which testmethod i can use for it?

In my textfile is written a number. If the number is higher than value x i want to get a bad status back. If the value is below x i want to get the good status.

Can you help me to make it possible?

Thanks,
Malus
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

You need to use Shell Script test with custom made script.

E.g. Custom JavaScript may look like the following:

Code: Select all

statusUnknown     = "ScriptRes:Unknown:";
statusOk          = "ScriptRes:Ok:";
statusBad = "ScriptRes:Bad:";

var objArgs = WScript.Arguments;

if (objArgs.length!=2) {
  WScript.StdOut.Write(statusUnknown + 'Required 2 parameters: <file path> <max val>');
  WScript.Quit();
}

fname = objArgs(0);
maxval = parseFloat(objArgs(1),10);
str = '';

try {
  var oFS = new ActiveXObject('Scripting.FileSystemObject');
  var oFile = oFS.OpenTextFile(fname);
  str = oFile.ReadAll();
  oFile.Close();
} catch(e) {
  WScript.StdOut.Write(statusUnknown + e.message+' ['+fname.replace(/\\\\/g,'\\')+']');
  WScript.Quit;
}

var fval = parseFloat(str,10);

if (fval>maxval) {
  WScript.StdOut.Write(statusBad + str);
} else {
  WScript.StdOut.Write(statusOk + str);
}
Start cmd: cmd /c cscript /B /E:JScript %Script% %Params%

Script requires 2 parameters: <path to the file> <max value>
Please note, if file path contain spaces, it shopuld be quoted. E.g.:
"D:\new logs\data.txt" 47
Post Reply