JavaScript to execute command line calls

  • bjhess
  • Student
  • Student
  • User avatar
  • Joined: Jun 04, 2004
  • Posts: 77
  • Loc: Owatonna, Minnesota
  • Status: Offline

Post August 27th, 2004, 7:32 am

Hi,

This isn't necessarily a web development question, but it does relate to web applications. I've written some Ant scripts to compile and package a java EAR. I want to execute these scripts via JavaScript running on Windows 2000. I simply cannot find any reference to executing command line calls via JavaScript.

Anyone know of some good documentation?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post August 27th, 2004, 7:32 am

  • Managedlinks
  • Proficient
  • Proficient
  • No Avatar
  • Joined: Mar 31, 2004
  • Posts: 294
  • Status: Offline

Post September 1st, 2004, 7:05 pm

Hi

You can't make command line calls from javascript
because its a serious security risk.

you could run the scripts by calling a CGI program from a web page, if thats what you want to do.
  • bjhess
  • Student
  • Student
  • User avatar
  • Joined: Jun 04, 2004
  • Posts: 77
  • Loc: Owatonna, Minnesota
  • Status: Offline

Post September 1st, 2004, 7:15 pm

I'm sure the answer is the same, but I should mention I'm talking about simply running JavaScript on a Windows box in this situation. It won't even be imbedded in a web page.
  • Managedlinks
  • Proficient
  • Proficient
  • No Avatar
  • Joined: Mar 31, 2004
  • Posts: 294
  • Status: Offline

Post September 1st, 2004, 7:28 pm

Yep sorry its the same answer

If you let me know why you want to do it this way I can suggest alternatives.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post September 1st, 2004, 7:33 pm

I'm not sure if this is what you mean, but you can use JScript with the Windows Scripting Host to execute shell commands via the Run method of the Shell object as in this example:

http://www.winscripter.com/WSH/System/105.aspx
Free Programming Resources
  • Managedlinks
  • Proficient
  • Proficient
  • No Avatar
  • Joined: Mar 31, 2004
  • Posts: 294
  • Status: Offline

Post September 1st, 2004, 7:46 pm

You are right of course.

but still "why" is the big question.

A batch file can do the same, or run it as a scheduled task. or a combination
  • bjhess
  • Student
  • Student
  • User avatar
  • Joined: Jun 04, 2004
  • Posts: 77
  • Loc: Owatonna, Minnesota
  • Status: Offline

Post September 1st, 2004, 7:57 pm

Basically I am using the Source Integrity change management tool from MKS, which can fire JavaScript based on certain tasks completed with the product (code promotion, file check-in, etc). I haven't dug into these "triggers" yet to determine if they are truly tightly bound to JavaScript, but if they are then I'd like to limit the technologies I'm using in my overall process as much as possible.
  • Managedlinks
  • Proficient
  • Proficient
  • No Avatar
  • Joined: Mar 31, 2004
  • Posts: 294
  • Status: Offline

Post September 1st, 2004, 9:08 pm

Sorry I am not familiar with that software.

If its a windows based tool then it probably uses jscript as its scripting engine, in which case as RichB says you should be able to access the shell object which will then run a command.

check out the link provided and also go to Microsoft msdn.microsoft.com and search for jscript or vbscript (they are pretty synonomous)
  • bjhess
  • Student
  • Student
  • User avatar
  • Joined: Jun 04, 2004
  • Posts: 77
  • Loc: Owatonna, Minnesota
  • Status: Offline

Post September 1st, 2004, 9:18 pm

Yep, it is a Windows tool and I'll definitely look into RichB's suggestion. Seems very similar to the vbscript methods.
  • Managedlinks
  • Proficient
  • Proficient
  • No Avatar
  • Joined: Mar 31, 2004
  • Posts: 294
  • Status: Offline

Post September 1st, 2004, 9:56 pm

Remember in windows lingo its jscript not javascript

good luck
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post September 1st, 2004, 11:22 pm

JScript is the Microsoft version of Javascript. JScript is very similiar in alot of ways and the sample RichB provided you with is written in JScript
Watch me grow
  • lifeinashish
  • Born
  • Born
  • No Avatar
  • Joined: Sep 03, 2009
  • Posts: 1
  • Status: Offline

Post September 3rd, 2009, 12:19 am

You obviously can run the DOS commands from JavaScript.
For this, In your script section add:
try{var wsh = new ActiveXObject('WScript.Shell');} catch(err){}

This will promp user to enable Activex.
Then you can run any of the command using:

wsh.Run("notepad.exe");

I hope it worked for you

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 229 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.