Windows java environment variables issue - javascript

After I set my java environment variables in Windows 10. It works at the first time, but after rebooting, when I executed the batch file, it would show that java command wasn't working.
Has anyone know what is going on? Below are my system variables, there's nothing in user variables
JAVA_HOME = C:\Program Files\Java\jdk-17.0.5
Path = %JAVA_HOME%\bin
When I go back to the setting page of environment variables, without any changes, after pressing apply, it suddenly works when opening the same batch file. I gotta do this process every time I reboot...

try this instead Path = C:\Program Files\Java\jdk-17.0.5\bin

Related

A bash script that will start when the EC2 instance is turned on

I have a EC2 instance, and I would like to write a script (never done them before) so that every time I start my E2 instance in the AWS console, the following files are run automatically.
Lets say I have a file called example.js which contains this:
var test(){
console.log('hello world');
}
test()
And then I have a similar file called example2.js
Everytime I run my EC2 instance, I need to ssh into it and do node example.js and node example2.js in order to run the functions.
However, I would like to write a startup script so that when the EC2 instance state is turned to running (i.e. online), I would like the command node example.js and node example2.js executed by themselves.
Is this possible? If yes, where do I put this script?
I have a Centos image running on my EC2 instance, and the EC2 instance is turned off at night, and turned back on in the morning - hence the script will simplify things!
I read this link, however cannot quite figure it out in my case: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
Any help will be appreciated. Thanks
use pm2. It's an excellent solution for managing node processes. Also can start the processes when you boot the machine.
ref: http://pm2.keymetrics.io/docs/usage/startup/
here is another good tutorials: https://futurestud.io/tutorials/pm2-restart-processes-after-system-reboot
Specific to EC2, you can use the 'User Data' option, available when you create your instance. It takes a script as input that will be executed at launch.
Here's how it looks like :
To add user data to your instance, wait until the night so you don't disrupt yor apps, then right click on it and do "Create Image".
Once the image is created, you can use it to spawn a "new" instance, with user data, and delete the old one without losing anything. Don't forget to reassign the elastic IP of the old instance :)
More information/documentation on aws.amazon.com

Debug remote mocha.js test with node-inspector?

I have a test file on a remote machine and I want to walk through it with node-inspector. So, on the remote machine (Vagrantfile):
node-inspector &
mocha --debug-brk foo.test.js
Then, on my dev machine I open Canary and go to:
http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858
However, I'm not able to debug my test, since the debugger will break at the first line in node_modules/mocha/bin/_mocha, and my test file isn't visible in the Sources tab:
I tried setting a breakpoint inside _mocha, on line 398:
runner = mocha.run(program.exit ? exit : exitLater);
But when I try to 'step into', to see the run function execute, it doesn't step in. I can see output in the console, so it does execute though. If I set a breakpoint directly in the run function, it won't break there.
Also, the test file never appears in the "Sources" tab so I can't set breakpoints in it. I also tried adding a debugger statement to it but it still doesn't break there.
How can I make node-inspector show the test file, and step through it ?
node v0.12.0
node-inspector v0.10.0
mocha v2.2.4
I frequently run into this, and I don't know if there's a better solution (if there is I'll be glad to hear it), but I find I have to let the debugger advance to a point where it becomes aware of the additional files I want to debug. Without seeing more of your code I can't give a more specific suggestion about where to advance to, but try to figure out where the test files will be loaded in the source files that are available and advance to there. It'll gradually add more files to the Sources panel as code runs.
There are actually 2 problems:
breakpoints not respected
test files not visible
The first problem was fixed in the recently released node-inspector#v0.10.1. So, breakpoints will be respected anywhere.
There is still the second issue. As #JMM said, the list of files in the 'Sources' tab is dynamic, and test files won't appear there when the process breaks. What I ended up doing is setting a breakpoint just before the test function is run, in mocha/lib/runnable.js#266, on this line:
var result = fn.call(ctx);
fn is the test function. Once you step into it, the test file will appear in the Sources tab and the debugger's cursor will be on the first line of the test function.

Javascript executing batch file that incorporates setting of environment variables for a per session basis

I'm working on creating a base for a batch file that is designed to 2 main things:
Set several environment variables
Executes a jscript file
When I exit the program that is run by the jscript file, I want the variables to unset themselves
Currently this is what I'm working with (actual variables and paths omitted):
SET EnvVar1=<path>
SET EnvVar2=<path>
C:\Windows\SysWOW64\wscript.exe //e:jscript "<PATH>\JSCRIPT.js"
Now, it appears to me that it's working, but I'm not used to writing batch files that incorporate environment variables and jscript files. When I do something similar to this and run an executable, the cmd window stays open and this confirms to me that the variables are staying set until I shut down the program. Is there anything similar that I can do with this project that would produce the same results? The intended purpose is to allow me to run multiple versions/builds of the same jscript/programs for testing purposes.
SETLOCAL
SET "EnvVar1=<path>"
SET "EnvVar2=<path>"
C:\Windows\SysWOW64\wscript.exe //e:jscript "<PATH>\JSCRIPT.js"
ENDLOCAL
setlocal command generates a copy of the environment. Any changes are done inside this copy. endlocal discards this copy, reverting the environment to the previous state.

How do I change the underlying Phantomjs object settings using Chutzpah?

We have some QUnit javascript tests running in Visual Studio using the Chutzpah test adapter. Everything was working fine until we changed our api (the one being tested by the js files) recently, and added some validations over the UserAgent http header. When I tried to update the tests to change/mock the user agent I realized it was not directly possible even by overriding the default browser property.
After a few days of scavenging, I finally found what exactly is happening. Chutzpah is creating a phantomjs page object for the test files to run on. This is being done on a base javascript file (chutzpahRunner.js) located at the Chutzpah adapter installation path. These are the last lines on the file, that effectively start the tests:
...
// Allows local files to make ajax calls to remote urls
page.settings.localToRemoteUrlAccessEnabled = true; //(default false)
// Stops all security (for example you can access content in other domain IFrames)
page.settings.webSecurityEnabled = false; //(default true)
page.open(testFile, pageOpenHandler);
...
Phatomjs supports changing the user agent header by specifying it in the page settings object. If I edit this chutzpahRunner.js file in my machine, and manually set the user agent there, like this:
page.settings.userAgent = "MyCustomUserAgent";
My tests start to work again. The problem is that this is not in the project itself, and thus cannot be shared with the rest of the team.
Is it possible to change the properties of the phantomjs objects created by Chutzpah to run the tests? I'd like to either change them from inside my own tests, or from another script file I could embed on the pipeline.
Without a code change in Chutzpah it is not possible to set those properties on the PhantomJS object. Please file an issue at https://github.com/mmanela/chutzpah asking for this functionality and then fork/patch Chutzpah to add it (or wait for a developer on the project to hopefully get to this).
Update:
I pushed a fix for this issue. Once this is released you can use the following in a Chutzpah.json file:
{
"userAgent": "myUserAgent"
}

WScript is undefined

I am trying to run a Javascript file locally, which is supposed to create a CSS image sprite using ImageMagick. It's part of the OpenID selector JS component: http://code.google.com/p/openid-selector/
The generate-sprite.js (http://code.google.com/p/openid-selector/source/browse/trunk/generate-sprite.js?r=140) file is supposed to create the image sprite automatically. However, whenever I run it in IE (the local version of the file, of course), I get the error SCRIPT5009: 'WScript' is undefined on line 19, character 1.
I have of course installed ImageMagick and updated the location in the js file. IE9 is letting the ActiveX execute.
Since I'm not familiar with WScript, I am completely lost. Googling didn't help, since this seems to be a very generic error.
Can somebody help diagnose this error please?
When you say you're "running" the JavaScript file locally, are you using Windows? If so, and double-clicking or typing the filename from the command line doesn't work, try:
wscript generate-sprite.js
...which explicitly invokes wscript.exe.
If you're not using Windows, you can't use that script — it relies on both Windows and Microsoft's JScript (which the wscript.exe program invokes).

Categories