I'm not an experienced JavaScript programmer. This is my first project using JS.
I'm developing on Linux and am at the point for my first release. Running the project on a Windows machine I came across the following ...
const os = require("os");
global.DBSysInfo;
console.log("DBSysInfo =\n" + DBSysInfo);
var pnt1 = DBSysInfo.indexOf('DBActive = "yes"');
console.log("pnt1 = " + pnt1);
var pnt2 = DBSysInfo.indexOf(os.EOL + os.EOL, pnt1) + 1;
console.log("pnt1 = " + pnt1 + "; pnt2 = " + pnt2);
console.log("DBSysInfo.substring =\n" + DBSysInfo.substring(pnt1, pnt2));
The above code works as expected on Linux:
DBSysInfo =
SysLocation = "C:\Users\mlake\MELGenKey"
DBActive = "yes"
DBName = "SOT2-KILLE20240704"
DBUserID = "2.0"
DBStatus = "1"
DBSecurity = "0"
DBLocation = "DBs/SOT2-KILLE20240704"
pnt1 = 42
pnt1 = 42; pnt2 = 176
DBSysInfo.substring =
DBActive = "yes"
DBName = "SOT2-KILLE20240704"
DBUserID = "2.0"
DBStatus = "1"
DBSecurity = "0"
DBLocation = "DBs/SOT2-KILLE20240704"
On Windows, the output is:
DBSysInfo =
SysLocation = "C:\Users\mlake\MELGenKey"
DBActive = "yes"
DBName = "SOT2-KILLE20240704"
DBUserID = "2.0"
DBStatus = "1"
DBSecurity = "0"
DBLocation = "DBs/SOT2-KILLE20240704"
pnt1 = 42
pnt1 = 42; pnt2 = 0
DBSysInfo.substring =
SysLocation = "C:\Users\mlake\MELGenKey"
I don't understand why the output would be different on Windows. Why would pnt2 be 0? The only thing I can think is the second "indexOf" statement is treating "DBSysInfo" as an array. If so, why? Is global treated differently on Windows than it is on Linux?
I tried using both Edge and Firefox on Windows with the same results, but the code is in node and I wouldn't think the browser used would make any difference in this instance.
\r\n
... linux\n
- what is the respective value ofos.EOL
in your code for linux and windows - perhaps whateverDBSysInfo
is always uses the linux "convention" regardless of the OSindexOf
is the same, but i think it's more likely your input is different. Many tools on windows write text files using different line endings for exampleconsole.log("\n".length)
is 1 butconsole.log(os.EOL.length)
is 2 - so, using the literal\n
is not the same as in some environments where\n
can be taken to mean\r\n
(I can't remember where that was, but I know it was many years ago that this tripped me up)global.DBSysInfo;
is a property access that doesn’t do anything, even as an assertion (ifglobal.DBSysInfo
doesn’t exist, there won’t be an error). Not sure if that was the intent.