在Windows命令行中运行JavaScript [英] Run JavaScript in a Windows Command Line

查看:75
本文介绍了在Windows命令行中运行JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天才发现的是JavaScript可以通过Windows命令行运行.

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

所以我发现要在Windows cmd.exe中使用cscript运行javascript文件.

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

我的hworld.js文件只有一行

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

它没有运行并显示错误

Microsoft JScript runtime error: Object Expected

在简单地运行一行JavaScript文件的cscript之前,我需要遵循以下步骤吗?

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

我给人以JavaScript即将用完的印象.

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

PS. Java是为我正在尝试的计算机设置的开发环境,已安装且功能正常

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

推荐答案

在控制台中打印文本的正确命令是

The right command to print text in the console is

WScript.echo("your text");

其余的工作原理与javascript非常相似.

The rest works pretty much like javascript.

这篇关于在Windows命令行中运行JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆