473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how can we use cscript.exe or wscript.exe to run javascripts?

hi all,

i want to run some javascript file from command line.
On searching the net i came to know that we can do it by using cscript.exe or with wscript.exe.

1. can some one provide me some example code(javascript )?
2. can we pass some arguments to the functions in the script file? or can we make it interactive in the commandline to read some values?
3. where can i get a complete reference to these problems ..

It ll be good if the example code can demonstrate all the important capabilities.

looking forward for a soon reply . .
Feb 28 '08 #1
3 13034
acoder
16,027 Expert Mod 8TB
See this thread (from the newsgroup archives). It's more JScript than JavaScript.
Feb 28 '08 #2
rnd me
427 Expert 256MB
if you have the .net framework installed, not only can you use the command line, you can turn your scripts into actual EXEs!

you have to find jsc.exe on your computer, and copy it to a work folder, or add the path of jsc.exe to your path environ variable.

just use the windows search to find it.

then have fun, and try some code:

save this as eval.bat
Expand|Select|Wrap|Line Numbers
  1. @echo off
  2. echo print(%1%2%3%4%5%6%7%8%9) > try.tmp.js
  3. jsc /nologo try.tmp.js
  4. try.tmp.exe
  5.  
then, you can do stuff like:

C:\Temp\jscript>eval 400 + 20
420


you can pass thing by the command line to your exes as well:
save this text as args.js, and run jsc.exe args.js

Expand|Select|Wrap|Line Numbers
  1. import System;
  2. import System.IO;
  3. import System.Net;
  4. import System.Text;
  5. import System.Windows.Forms;
  6. var url="";
  7. var addy="";
  8. var dump="";
  9. var CMDarguments : String = Environment.GetCommandLineArgs() || ",";
  10. print (CMDarguments )
  11.  
C:\Temp\jscript\simples>args.exe this seems to work
args.exe,this,seems,to,work




this one will let you "pipe" stdout to your js exe:
in this case, it pastes the text from the command line to the clipboard, another IO point you can use.

Expand|Select|Wrap|Line Numbers
  1. import System;
  2. import System.Windows.Forms;
  3.  
  4. var Console = System.Console;
  5. var cb= System.Windows.Forms.Clipboard;
  6. var scc = String.fromCharCode;
  7.  
  8.  
  9. //var chars : String = "";
  10. var chars=[];
  11. var len : int = 0;
  12. var i : int;
  13. var c : String;
  14.  
  15.  
  16. while (true)
  17.     {
  18.          i = Console.Read ();
  19.          if (i == -1) break;
  20.          c = scc(i);
  21.          chars[len++]=c;
  22.     }
  23.  
  24.  
  25. cb.SetDataObject( chars.join("") , true );
  26. Console.WriteLine(chars.join(""));
  27.  
if i compile above as paste.exe for example:

Expand|Select|Wrap|Line Numbers
  1. echo %date% | paste.exe
  2.  
will place today's date on the clipboard.


if you are looking for something specific, ask me, but this should get you started.
also, you can find full .NET documentation online.
although it is slightly more complicated than browser javascript, it has much the same syntax and many of my functions have been pasted from browser code without any editing.

good luck!
Feb 29 '08 #3
hi,

actually i am using javascripts and html to generate some text files.
the entire thing is purely client side and it resides in the users hard disk.

there are some 10 files that are to be generated and i have 10 html pages with the generate file button in each page to generate the 10 files.

now i want to generate it from command line so that the user need not open the ten pages and click the generate file button on each page.

if i can do this with the help of batch fies then the job becomes simple. (in future it may be requried to genrate more files).

steps i have planned to do this are :

1. write a .js which contains the script that genrates the files ..
2. place the location of this .js file in a textfile.
3. write a batch file that reads the .js file location from this text file and then execute it with the help of cscript .exe or something ..
4. i don want any user interaction in the command line. if the .js file location is changed on the hard disk then it will be updated in the text file.

please help . . .i am a newbie ..
Mar 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Alex Ang | last post by:
I have written the following VBScript program. It is stored into a file "map_drive.vbs". It successfully mapped to a network drive \\server1\data. Dim WshNetwork Set WshNetwork =...
0
by: Brendon Rogers | last post by:
I am using IIS5.0 Am attempting an ASP solution to create Windows 2000 user accounts, Exchange 5.5 mailboxes, home drives etc. So far so good but I am having a problem trying to NTFS-permission...
4
by: David Virgil Hobbs | last post by:
My web host inserts banner ads into my html pages. The javascript in these banner ads interferes with the onload triggered javascript functions in my pages. Whether I trigger my javascript...
1
by: Sandeeo | last post by:
Can I execute javascript file with CScript.exe under windows like we use VBScript ? If yes, can someone give post an example. Thanks Sandeep
0
by: bfonseca3 | last post by:
Hi, i have a query made using wmi and i would like to transform this to be viewed from a website. I have installed a iis and asp.net 2.0. Can anyone help me to re-arrange the code to be able to...
0
by: AirYT | last post by:
Done a bunch of searching on this topic and i have come up with nothing. I have a .vbs script that i wish to execute by calling an asp page. i am working on a W2K server with IIS5.0 & SP4. ...
12
by: pantagruel | last post by:
Hi, I'm thinking of making a WScript based JavaScript library, I can think of some specific non-browser specific scripting examples that should probably make it in, like Crockford's little...
2
by: AbdulBaari | last post by:
Dear all, can anyone solve this problem. Im beginner in VBScript.Im getting an errorregarding "Wscript" means whenever I use WScript object, it shows Errors as " Object required: WScript" &...
0
by: .nLL | last post by:
Erorr is --------------------- Microsoft VBScript runtime error '800a0046' Permission denied /a.asp, line 3 -----------------------
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.