1

I have a .js file that I am not allowed to modify. I can execute it by opening cmd.exe and entering the following:

cscript my_script.js

When I do that, the script runs to completion, and once it is done, it keeps the command prompt open so that I can read its output.

Since I don't want to go through those steps every time I need to execute a .js file, I rick clicked my_script.js, selected the "Open with" option, and set cscript.exe as the default program to run .js files.

After doing that, I am now able execute my_script.js by double clicking it. This is exactly what I wanted, but a new issue has arisen: once my_script.js finishes executing, the command prompt where the output is displayed closes automatically.

I have read the answers to other questions that describe how to fix this issue, but none of them apply to my particular situation (I am not allowed to modify the .js file).

Is there a way to keep the command prompt open after the .js file finishes executing?

2
  • How about outputting the script result into a text file? So make a batch file that has cscript my_script.js >> C:\temp\output.log and then you can read the output.log at your leisure?
    – Darius
    Commented Jan 29, 2018 at 14:42
  • 1
    You may find SS64's reference page on CMD to be useful, specifically the /K switch. Commented Jan 29, 2018 at 15:01

1 Answer 1

1

You can create a simple batch file that will open the command prompt, run your script and pauses after executing so that you can read the output.

Open a text editor and enter the following lines:

@ECHO OFF
cscript my_script.js
pause

Then save this as a .bat file. When you want to run the script you can simply run the batch file. The above example assumes that the batch file resides in the same folder as the script. Otherwise use:

cscript "\\yourpath\my_script.js"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .