Windows – How to run .js file from a command line on windows

command linewindows 7

I have a shortcut with 'target' "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js".

I want to run that from a batch file so I copied the "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js" into cmd.exe command line and pressed enter. Nothing happened.

How can I run "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js" from a command line on Windows7?

update

the js file contains

var WshShell = new ActiveXObject("Wscript.Shell");
WshShell.run("java -Dlog.dir=%TEMP% -jar taf-loader.jar", 0, false);
WScript.exit;

I tried to run the js file with both Wscript.exe and Cscript.exe as @Serge suggested but nothing worked = the program I start by doubleclicking hasn't started. No error either.

C:\>Cscript.exe "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js"
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.


C:\>Wscript.exe "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js"

C:\>

Best Answer

You have two options:

Cscript.exe "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js"

or

Wscript.exe "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js"

The former one starts the command line version of Windows Scripting Host and the latter one is starting the window version.

The command line options are documented here: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cscript

and here: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/wscript

In your script file you should use the full path to your jar file and possibly full path to the java.exe

Alternatively, to allow the java.exe locate the tar-loader.jar file you should change the current directory to the one containing this file, so before invoking wscript make cd "C:\Users\Public\TestPro\TestPro Automation Framework\"

As you mentioned that you like to run this script in a single touch, you also may create a shortcut on your desktop that has a command line set to Wscript.exe "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js" and working directory set to C:\Users\Public\TestPro\TestPro Automation Framework\

Related Question