473,398 Members | 2,812 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,398 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 13064
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.