1

Some background: In my Rails environment I'm using CoffeeScript which uses ExecJS which uses the Windows Scripting Host to execute Javascript files.

Unfortunately I'm experiencing huge delays (> 30 seconds) when my CoffeeScript files are compiled.

Using Process Explorer and Process Monitor I already identified the command line as one of the causes. cscript.exe expects its parameters with double slashes:

cscript //E:jscript //Nologo //U C:/path_to_coffeescript_compiler.js

For some reason cmd.exe (not cscript.exe!) treats the double slashes as double backslashes and tries to resolve the network name of each parameter which obviously fails, but not after some delay.

Here's a small excerpt of the Process Monitor log:

cmd.exe     CreateFile     \\E:jscript\\             OBJECT PATH INVALID
cmd.exe     CreateFile     \\E:jscript \Nologo\\     BAD NETWORK PATH
cmd.exe     CreateFile     \\E:jscript \Nologo \U\   BAD NETWORK PATH
cmd.exe     CreateFile     \\Nologo\\                OBJECT PATH INVALID
cmd.exe     CreateFile     \\Nologo \U\              BAD NETWORK PATH

... and so on.

What can I do to prevent this?

Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
  • Hmm... I cannot reproduce this (procmon shows no activity regard phony network paths). What happens when you replace the `cscript` with something else, for example `echo`. If really `cmd.exe` does something funny here, it should happen there as well. Also, do you invoke `cscript` from an interactive shell or from a batch file. You might want to post the output of `echo %CMDCMDLINE%`. – Christian.K Apr 30 '12 at 11:09
  • Funny, it doesn't happen with `echo`, or any other executable, but it happens with `wscript.exe`. The command line is generated by `ExecJS`, where it starts `cmd.exe` with the `/c` switch. Also the delay doesn't happen on *every* call. From ExecJS it's almost every time, but from my own command line it happens about half of ever time. – Daniel Rikowski Apr 30 '12 at 11:17
  • I assume you did see the actual command line with e.g. Process Explorer, but could it be, that for some reason it generates something like `cmd /C //E:...`, i.e. accidentally leaves out the `cscript.exe`? Also, does the error also happen, when you simply run `cmd /c "cscript //E:jscript //Nologo //U C:/path_to_coffeescript_compiler.js"` from a plain CMD window? – Christian.K Apr 30 '12 at 11:20
  • No, `cscript` is actually there. (Otherwise my CoffeeScript files wouldn't be compiled) Manually calling `cmd /c "cscript ..."` shows the same behavior. – Daniel Rikowski Apr 30 '12 at 11:22

2 Answers2

3

After I did some more hacking I finally found the problem. The culprit was Comodo Internet Security which injected a DLL into the cmd.exe process which did the lookups:

Help text for the option Do heuristic command-line analysis for certain applications:

Selecting this option instructs Comodo Internet Security to perform heuristic analysis of programs that are capable of executing code such as visual basic scripts and java applications. Example programs that are affected by enabling this option are wscript.exe, cmd.exe, java.exe and javaw.exe.

Thanks to all offering workarounds. The fact that none of these worked guided me into finding the cause :)

Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
1

I have no understanding of what process is at fault, but you could try to hide the // from said process.

Idea 1) Put the CSCRIPT command in a batch file and then have ExecJS call the batch file.

Idea 2) Delay the appearance of the // using a FOR variable

for %s in (/) do cscript %s%sE:jscript %s%sNologo %s%sU C:/path_to_coffeescript_compiler.js

Note - This doesn't explain much, but most Windows contexts will accept a / in place of a \. For exampe, DIR "C:/" is equivalent to DIR "C:\".

dbenham
  • 127,446
  • 28
  • 251
  • 390