Debugging jscript in WSH



  • I have a current need to adapt some stuff I wrote and tested in Chrome for standalone use with WSH/jscript right now, and of course it's not working because jscript, and I really can't be arsed doing it all by inserting WScript.Echo and could use a graphical WSH jscript debugger.

    I have vague memories of achieving jscript debugging with some part of Office in the past, but I'm working with machines that have Office 2010 and apparently that's all gone now. And yet @blakeyrat says that there is a way to do this that's at least as easy as debugging cmd scripts.

    So what is it? Apparently I'm one of those morons who is too dumb to use it, because I've been poking about with the googles for an hour now and achieving nothing.

    I got as far as installing the Windows Script Editor component from Office 2007, and making that be the thing that opens .js files, and it opens my test script in an editor; but when I hit F5 to run it or F11 to single-step it, I just get a window titled "View Downloads - Internet Explorer" asking me whether I want to open or save my file.

    Easy this ain't.



  • @flabdablet From what I can find, the original debugging tool was deprecated in favour of the Office tool (and while still available, isn't guaranteed to work on modern Windows), and the Office tool has itself been deprecated, leaving your only option being to put the script in a dummy webpage and use IE's debugging tools



  • @RaceProUK IE doesn't have the WScript global object, though, does it? Makes it hard to use that for debugging stuff that's going to run standalone via cscript/wscript.



  • @flabdablet said in Debugging jscript in WSH:

    IE doesn't have the WScript global object, though, does it?

    My limited testing indicates that it does not



  • @flabdablet said in Debugging jscript in WSH:

    I got as far as installing the Windows Script Editor component from Office 2007, and making that be the thing that opens .js files, and it opens my test script in an editor; but when I hit F5 to run it or F11 to single-step it, I just get a window titled "View Downloads - Internet Explorer" asking me whether I want to open or save my file.

    You're doing the right thing, but I can't for the life of me figure out how you're getting the result you're getting.

    What happens when you double-click a .js file in Explorer? Have you changed the Open With settings so that they end up opened in IE instead of Windows Scripting Host?



  • @blakeyrat No, I changed the Open With settings so that .js files open in C:\Program Files\Common Files\Microsoft Shared\OFFICE12\MSE7.EXE. Then I double-click hello.js containing just

    WScript.Echo('Are we having fun yet?');
    

    and it opens up in what appears to be an IDE. Then I hit F5, and the "View Downloads - Internet Explorer" window appears.

    All of this is in a 32 bit install of Windows 7, if it matters.



  • @flabdablet Oh. MSE is a IE JavaScript debugger. It's doing what it's supposed do.

    What you want is the confusingly-similarly-named MSD, Microsoft Script Debugger, which is a mini-IDE for JScript and VBScript.

    https://www.microsoft.com/en-us/download/details.aspx?id=22185

    Note that this is the same debugger that shipped with like... Windows 2000 and is kind of rough. But it works.

    I did some Googling to see how you're supposed to do it in the modern era, and I'm having no luck. This stuff is all deprecated in favor of PowerShell now, but it's weird MS doesn't have more modern tools for the thousands of WSH scripts still out there.

    Visual Studio used to do it, but it looks like as of 2015 in Windows 10 that no longer works?

    Check this post:

    http://stackoverflow.com/questions/32262978/visual-studio-2015-wont-debug-wsh-scripting-languages-anymore

    See if that registry change makes WSH call up the VS debugger.

    If you have an older VS, like 2008, handy try just installing it. It all might still work fine. But I don't know for sure.



  • @blakeyrat said in Debugging jscript in WSH:

    this is the same debugger that shipped with like... Windows 2000 and is kind of rough. But it works.

    Tried it on Windows 7. Had to use XP+SP3 Compatibility Mode to make it run at all. Then it didn't debug anything. Well, it didn't hook into the //D //X command line options on cscript.exe or wscript.exe at any rate.

    I will try it again and see whether I have better luck opening a .js file in it explicitly.

    Edit: OK, I did exactly the same installation of the mouldy old Microsoft Script Debugger on this 32 bit Windows 7 installation as I did on that other 32 bit Windows installation, and this time it doesn't need XP+SP3 compatibility mode and it does get triggered when I do cscript //d //x yow.js. There's the old Microsoft determinism in operation again.

    Also, cscript /d /x yow.js does exactly the same thing. I have no idea why they document those switches with the double slash.

    Edit edit: oh looky! You can use - as the switch introducer for cscript.exe and wscript.exe and that works too. -- doesn't though.

    Edit edit edit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options has no cscript.exe subkey or value at all, on the box where the debugger is working.

    This stuff is all as confusing as fuck, and PowerShell scripts still can't be relied on to launch when you double-click them. And you wonder why I still claim there's a use case for cmd? It is, in your words, "kind of rough"... but it fucking works. every. time.

    Thanks for your help.



  • @flabdablet So you weren't asking help, you were just trying to find a new and creative way to call me an idiot. Well thanks I guess. I appreciate the creativity at least.



  • @blakeyrat No. I was genuinely asking for help, all my best efforts having failed. You provided help. It helped. I thanked you for your help (after venting a bit). Where is 'idiot'?


  • Winner of the 2016 Presidential Election

    @flabdablet said in Debugging jscript in WSH:

    @blakeyrat No. I was genuinely asking for help, all my best efforts having failed. You provided help. It helped. I thanked you for your help (after venting a bit). Where is 'idiot'?

    The thanks for your help probably sounded a little sarcastic after your venting...



  • @flabdablet said in Debugging jscript in WSH:

    adapt some stuff I wrote and tested in Chrome for standalone use with WSH/jscript

    @RaceProUK said in Debugging jscript in WSH:

    put the script in a dummy webpage and use IE's debugging tools

    @flabdablet said in Debugging jscript in WSH:

    IE doesn't have the WScript global object, though, does it? Makes it hard to use that for debugging stuff that's going to run standalone via cscript/wscript.

    ...well, neither does Chrome...

    What's this script supposed to do?



  • @sloosecannon OK. Well, just to be perfectly clear about this: I have benefited from @blakeyrat's help, which I appreciate his having taken the time to offer.

    @blakeyrat: thanks for your help. And I mean that in the most uncomplicated, unsarcastic, straightforward and genuinely grateful sense possible.

    The fact that I consistently have as much unpredictable, mysterious, maddening trouble with the technologies you like as you have with the technologies I like has no bearing on my appreciation for the help you've given me here.



  • @flabdablet said in Debugging jscript in WSH:

    @blakeyrat: thanks for your help. And I mean that in the most uncomplicated, unsarcastic, straightforward and genuinely grateful sense possible.
    The fact that I consistently have as much unpredictable, mysterious, maddening trouble with the technologies you like as you have with the technologies I like has no bearing on my appreciation for the help you've given me here.

    Don't worry dude, it was pretty clear you were just venting and meant no slight against blakeyrat.

    Blakeyrat is just terrible at understanding nuances in human communication, as usual.



  • OK, so. For the benefit of future readers if any:

    Turns out that if you have ever installed MS Office 2007 on a Windows 7 box, and then uninstalled it, it doesn't uninstall clean. The Office uninstaller leaves behind enough script debugging stuff to break subsequent attempts to install the (old, unsupported) Microsoft Script Debugger.

    The (old, unsupported) Microsoft Script Debugger's installer does a number of horrible things, including shoving assorted bits and pieces directly into System32. One of those is mdm.exe, a version of the Machine Debug Manager. On a box where MS Office 2007 has ever been installed, there will already be a newer Machine Debug Manager running as an auto-started service. Under these conditions, the first invocation of cscript /d /x somescript.js will bring it up in the Microsoft Script Debugger; subsequent invocations will behave as if no debugger was installed. Reinstalling MSD over the top of itself might get you one more successful debug session.

    Using the Services control panel to stop the Machine Debug Manager service and set its startup type to Manual, then re-doing the MSD installation, makes it all work.

    The leftover Office 2007 stuff, including the newer mdm.exe, is all under C:\Program Files\Common Files\microsoft shared\VS7DEBUG and there is a metric shitload of Registry references to stuff under that folder. The only vaguely uninstaller-related Registry reference is a scrambled GUID that if unscrambled would end in 0FF1CE; I haven't been game to try cleaning this particular Augean stable by hand, since just not using the Machine Debug Manager service it provides does seem to get the job done for me.

    And incidentally, it turns out the reason my stuff worked in Javascript under Chrome but not in Jscript under WSH is because of differences in the match array returned by the exec method on a regular expression object. In Javascript, submatches that fail to match anything don't create entries in the match array; in Jscript, they create entries containing empty strings. This makes it impossible to tell the difference between a submatch that didn't match and one that matched an empty string, which is an absolutely typical piece of Microsoft retardedness. They really don't get regular expressions, and never have. Grrr.



  • @flabdablet In JavaScript, the empty string is falsy; you test for this as such:

    var s = '';
    if (!!s) {
        //String is not empty
    } else {
        //String is empty
    }
    

    null and undefined are also falsy, and can be tested in the same manner.



  • @RaceProUK Quite so, but that doesn't have much bearing on the success or otherwise of using a match[2] == null test to work out whether the second submatch in a capturing regex (a) matched some possibly empty string or (b) simply didn't trigger at all.



  • @flabdablet said in Debugging jscript in WSH:

    impossible to tell the difference between a submatch that didn't match and one that matched an empty string

    Unless you wrote it, in which case you should probably know whether it could match an empty string.



  • @anotherusername Yes I did, and yes it could, which is why I needed (and can have, with any Javascript engine other than Jscript) a reliable way to distinguish an unreached submatch from one that was reached and then matched the empty string.

    I don't need that any more because I rejigged the regex stuff to work around it. Only reason I mentioned it here is because it's a non-obvious difference between Jscript and every other Javascript that the Jscript spec doesn't cover; one more little scatnugget to file under "yeah, Microsoft fucks that case up, avoid in production code".



  • @flabdablet A submatch that can match an empty string (and do so meaningfully) just sounds like :doing_it_wrong:. Like you were trying to do too much with regex in the first place.


  • Discourse touched me in a no-no place

    @anotherusername It depends very much on what you're doing. It's wrong to leap to conclusions…


  • sockdevs

    @RaceProUK said in Debugging jscript in WSH:

    if (!!s) {
    

    late to teh party i know, but the type coersion is unecessary here. if works on truthyness not booleanness.

    the double negate trick is useful when you need to turn truthiness or falsiness into actual truth or fiction. such as for persisting to a database or external API



  • @dkf said in Debugging jscript in WSH:

    It depends very much on what you're doing

    I'd be open to someone trying to present a situation where that could be useful and not :doing_it_wrong:.

    I can see how it'd be useful if you're replacing the match, and want to insert something if the context is matched but not captured. But if you're actually planning on looking at the stuff that was matched, why not just match it?


  • Discourse touched me in a no-no place

    @anotherusername said in Debugging jscript in WSH:

    But if you're actually planning on looking at the stuff that was matched, why not just match it?

    So you never need to know if something optional is present, and if so, what it is? That must be nice for you.



  • @dkf said in Debugging jscript in WSH:

    need to know if something optional is present, and if so, what it is?

    That is not exactly what he was talking about:

    @flabdablet said in Debugging jscript in WSH:

    tell the difference between a submatch that didn't match and one that matched an empty string


  • Discourse touched me in a no-no place

    @anotherusername Well, you can construct REs that contain subexpressions that can match the empty string or fail to match. A classic example is to put an anchor in there. If abc(d*$)? is given the string abce (and you're not using one of those modes which forces everything to be anchored overall since you're not a horrible heretic who needs to be first up against the wall when the revolution comes) then the overall RE matches, but the sub-RE does not. Given the input string abc, the sub-RE does match, and matches the empty string.



  • @dkf when I test that, it doesn't match (d*$)? when it's an empty string that matches unless it's forced to by removing the ? and making the subexpression non-optional. Then it matches "":

    Firefox:

    0_1462392713026_Untitled.png

    Chrome:

    0_1462392862043_Untitled.png

    Internet Explorer:

    0_1462392985827_Untitled.png

    So, based on that, I'm inclined to think that when it's given the input string "abc", the sub-RE does not match. I'm not sure why not (it matches just fine when it's given "abcd"), but it doesn't.

    edit: it looks like the behavior in Windows Script Host is different:

    0_1462394037272_Untitled.png

    (that first line is just to verify that my array stringifier function does produce the expected result when given an array with undefined in it.)


  • Discourse touched me in a no-no place

    @anotherusername Did you know that this is one of the cases that varies according to which RE engine is in use? This is area is very gnarly, and holds more dragons than you can shake a stick at.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.