Run JavaScript in a Windows Command Line

廉价感情. 提交于 2019-12-23 04:12:20

问题


This is something I only found out about today is that JavaScript can be run through a windows command line.

So I found out that to run a javascript file in windows cmd.exe you use cscript.

My hworld.js file only has one line

print('hello world');

I try to run this through the command line with

cscript /Prog/hworld.js

It didn't run with the error

Microsoft JScript runtime error: Object Expected

Are there steps i need to follow before simply cscript running a one line javascript file.

I was under the impression that JavaScript will just run out the box.

PS. Java is the development environment set up for the computer I am trying this on, installed and functional


回答1:


The right command to print text in the console is

WScript.echo("your text");

The rest works pretty much like javascript.



来源:https://stackoverflow.com/questions/28881184/run-javascript-in-a-windows-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!