JavaScript to execute command line calls

  • bjhess
  • Student
  • Student
  • User avatar
  • Posts: 77
  • Loc: Owatonna, Minnesota

Post 3+ Months Ago

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?
  • Managedlinks
  • Proficient
  • Proficient
  • Managedlinks
  • Posts: 294

Post 3+ Months Ago

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
  • Posts: 77
  • Loc: Owatonna, Minnesota

Post 3+ Months Ago

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
  • Managedlinks
  • Posts: 294

Post 3+ Months Ago

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
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

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
  • Managedlinks
  • Proficient
  • Proficient
  • Managedlinks
  • Posts: 294

Post 3+ Months Ago

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
  • Posts: 77
  • Loc: Owatonna, Minnesota

Post 3+ Months Ago

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
  • Managedlinks
  • Posts: 294

Post 3+ Months Ago

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
  • Posts: 77
  • Loc: Owatonna, Minnesota

Post 3+ Months Ago

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
  • Managedlinks
  • Posts: 294

Post 3+ Months Ago

Remember in windows lingo its jscript not javascript

good luck
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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
  • lifeinashish
  • Born
  • Born
  • lifeinashish
  • Posts: 1

Post 3+ Months Ago

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 39 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.