CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Need help with basic JavaScript (http://www.codingforums.com/showthread.php?t=285628)

titaniumshovel 01-11-2013 06:44 PM

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.

WolfShade 01-11-2013 07:52 PM

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.

Old Pedant 01-11-2013 08:12 PM

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.

titaniumshovel 01-11-2013 08:15 PM

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?

Old Pedant 01-11-2013 08:29 PM

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.

Old Pedant 01-11-2013 08:31 PM

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

felgall 01-11-2013 09:03 PM

Quote:

Originally Posted by Old Pedant (Post 1305558)
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.

Old Pedant 01-11-2013 09:12 PM

Quote:

Originally Posted by felgall (Post 1305567)
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.

titaniumshovel 01-14-2013 06:23 PM

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.


All times are GMT +1. The time now is 03:19 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.