Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need help with basic JavaScript

    Hello,

    I'm using TestComplete 9 to minimize user testing for new software releases. One of it's features is TestExecute, which runs your tests. I can have it open and run a test from the Command Prompt by writing one line of code.

    I've never used JavaScript (or any scripting language), but I would like to write a basic script that would open the command prompt, enter the line of code, hit enter, and then close the Command Prompt. My plan is to place the script file in Windows Scheduler and have it run every 15 minutes.

    I don't know where to begin, though. I'm not sure where to write it or how to write it.

    Any help or useful links to where I can learn?

    Thanks.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I don't think you can do that. JS doesn't interact with the OS, just the browser. Security issue, and all that.

    You can try VB, or Task Scheduler.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,719
    Thanks
    80
    Thanked 4,514 Times in 4,478 Posts
    Sorry, Wolfshade, you are wrong.

    On Windows, you can execute a ".js" file from the command line.

    Example:
    Code:
        cscript anyname.js
    And you can even pass along command line parameters and then read those in your JS code:
    Code:
        cscript updateSchedule.js "1/14/2013"
    There's also a "wscript" that invokes the JS code in a more windowing environment, but I haven't seen much use for it.

    You can also simply double click on a a ".js" file and have it automatically executed by the "cscript.exe" (which is part of the Windows Script Host -- WSH -- system).

    And, finally, yes you can use the JS code to in turn invoke other executables, using the WshShell ActiveXObject.

    Having said all the above, it seems likely that indeed Titanium could do this via JS (and, yes, you can use the Task Scheduler to invoke cscript and JS, of course--I do it all the time). But why?

    You could just as easily invoke TestExecute directly from the Task Scheduler. Unless the aim is to (for example only) randomly choose a different thing for TestExecute to do every 15 minutes, I don't see the need for JS to get involved here.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    titaniumshovel (01-11-2013)

  • #4
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    TestExecute works differently than other programs. It knows what to open up by using the Command Prompt's input.

    Any help or links I could use to figure out how to write a basic JS script to do something like this?
    Last edited by titaniumshovel; 01-11-2013 at 08:17 PM.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,719
    Thanks
    80
    Thanked 4,514 Times in 4,478 Posts
    I say again: Unless you will pass *DIFFERENT* parameters to TestExecute each time, you do *NOT* need JavaScript to get involved.

    You *CAN* just specify the command line arguments via the Task Scheduler. Did you not know that?

    And even if you couldn't, you could instead create a ".bat" file that contained something like
    Code:
        TestExecute  zambonis 337 Z$4
    and then schedule the ".bat" file.

    You need to explain why you think you need JS to get involved here.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,719
    Thanks
    80
    Thanked 4,514 Times in 4,478 Posts
    Here's the link to WSH:
    http://msdn.microsoft.com/en-us/libr...(v=vs.84).aspx

    And you can see the link to JS there, as well:
    http://msdn.microsoft.com/en-us/libr...(v=vs.84).aspx
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by Old Pedant View Post
    Here's the link to WSH:
    http://msdn.microsoft.com/en-us/libr...(v=vs.84).aspx

    And you can see the link to JS there, as well:
    http://msdn.microsoft.com/en-us/libr...(v=vs.84).aspx
    Those options run JScript though rather than JavaScript and the options available to use in the code are slightly different from what is available when you run JScript in a browser (eg. in IE8) - not that there are any significant differences between JavaScript and JScript in those parts of JScript that can run in those environments.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,719
    Thanks
    80
    Thanked 4,514 Times in 4,478 Posts
    Quote Originally Posted by felgall View Post
    Those options run JScript though rather than JavaScript and the options available to use in the code are slightly different from what is available when you run JScript in a browser
    100% agreed. But this was clearly what the original poster was looking for.

    It's trivial to schedule a JS script with the Windows Task Scheduler in this way.

    On two different sites that I manage, we use exactly this to perform various database cleanup and setup tasks. Some tasks run once a day, at night. Others run once an hour during the day. And all are more complex than I would care to try to do using a stored procedure, since they involve multiple steps that depend on each other. It is *SO* much easier to use a scripting language for this than it would be to do any other way.

    It's really no different than using CRON and a shell script on Linux. Which I have done many times before, also. But the Windows command language is just nowhere near as rich as, say, C-shell on Linux. So we need something more powerful, and JScript fills the bill very nicely. It's even easier to understand then some of the arcane structures needed in shell scripts.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry for the late response, but thank you OldPedant for your help. I honestly was not sure what I was looking for, so apologies for my ignorance on JS. And I didn't know that I could just pass the command line arguments into Task Scheduler. I've got it all set now, thanks again.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •