Javascript 使用Bash在JScript中更快地搜索

Javascript 使用Bash在JScript中更快地搜索,javascript,bash,jscript,Javascript,Bash,Jscript,我使用以下JScript代码搜索文件中的字符串: var myFile = aqFile.OpenTextFile(fileToSearchIn, aqFile.faRead, aqFile.ctANSI); while(!myFile.IsEndOfFile()) { s = myFile.ReadLine(); if (aqString.Find(s, searchString) != -1) Log.Checkpoint(searchString

我使用以下JScript代码搜索文件中的字符串:

  var myFile = aqFile.OpenTextFile(fileToSearchIn, aqFile.faRead, aqFile.ctANSI);

  while(!myFile.IsEndOfFile())
  {
    s = myFile.ReadLine();
    if (aqString.Find(s, searchString) != -1)
      Log.Checkpoint(searchString + " found.", s); 
  }

  myFile.Close();
这相当慢。我正在考虑使用bash命令来加快文件搜索过程:

  var WshShell = new ActiveXObject("WScript.Shell");
  var oExec = WshShell.Exec("C:\\cygwin\\bin\\bash.exe -c 'cat \"" + folderName + "/" + fileName + "\"'"); 
  while (!oExec.StdOut.AtEndOfStream)
    Log.Checkpoint(oExec.StdOut.ReadLine());
  while (!oExec.StdErr.AtEndOfStream)
    Log.Error(oExec.StdErr.ReadLine());

由于每次启动bash.exe时都会打开一个新窗口,因此搜索速度不会比以前快。是否有可能使用另一个开关在后台运行bash?

每次调用
WshShell.Exec
都会启动一个代价高昂的新进程。如果文本文件不太大,这将阻止生成新进程:

var myFile = aqFile.OpenTextFile(fileToSearchIn, aqFile.faRead, aqFile.ctANSI);
var myFileData = myFile.Read(myFile.Size);
var index = myFileData.indexOf(searchString);
if(index>0)
{
  Log.Checkpoint(searchString + " found.", index); 
}
myFile.Close();
这将不会打印整行,而是打印找到的位置的索引。如果需要整行,请从此处搜索行尾