Tal Tene
asked on
Powershell script needs "warm up" to run from java code
Hi all,
I need to run ps scripts from my java code in order to set performance monitor counters value.
For that I use the following line:
The problem is, that unless I first run the script from the ISE, it wouldn't set the counter value from the code, and from my perspective, the script simply won;t execute or is not usefull from the java code.
How can I fix this stauts?
Tal
I need to run ps scripts from my java code in order to set performance monitor counters value.
For that I use the following line:
final String PS_COMMAND = "Powershell.exe -executionpolicy Unrestricted -File .\\myscript.ps1";
Runtime.getRuntime().exec(PS_COMMAND);
The problem is, that unless I first run the script from the ISE, it wouldn't set the counter value from the code, and from my perspective, the script simply won;t execute or is not usefull from the java code.
How can I fix this stauts?
Tal
ASKER
Hi Guy,
I tried your proposal.
Now I get:
Thanks!
I tried your proposal.
Powershell.exe Set-executionpolicy Unrestricted -File .\\perfmon_create_jcm_counters.ps1
Now I get:
Set-ExecutionPolicy : A parameter cannot be found that matches parameter name 'File'
Thanks!
Hang on, did you run it in an Admin powershell locally? or did you update the PS1 script call?
That error tells me you probably updated the script to something like this:
final String PS_COMMAND = "Powershell.exe set-executionpolicy Unrestricted -File .\\myscript.ps1";
That would be incorrect as you are calling the set-executionpolicy cmdlet which has no -file argument. try this instead
That error tells me you probably updated the script to something like this:
final String PS_COMMAND = "Powershell.exe set-executionpolicy Unrestricted -File .\\myscript.ps1";
That would be incorrect as you are calling the set-executionpolicy cmdlet which has no -file argument. try this instead
final String PS_COMMAND = "Powershell.exe set-executionpolicy ByPass -File .\\myscript.ps1";
Yup, That's incorrect. I just did what I told you not to do... lol - I forgot to remove the "set-"
Updated
Updated
final String PS_COMMAND = "Powershell.exe -executionpolicy ByPass -File .\\myscript.ps1";
ASKER
Alright, lets try this slightly differently.
Replace the string with this...
Replace the string with this...
final String PS_COMMAND = "cmd /c powershell -ExecutionPolicy RemoteSigned -noprofile -noninteractive -File .\\myscript.ps1";
ASKER
Are you sure powershell script is being called? I would suggest you create a PS1 with
You are welcome to send the script, I'll happily have a look for you.
Drop me a PM and I'll send you my email address to send the script to.
Please make sure there is no confidential info in it.
Regards
Guy
New-Item c:\Temp\new_file.txt -type file
Rerun the Java applet and make sure once it completes the file has been created.You are welcome to send the script, I'll happily have a look for you.
Drop me a PM and I'll send you my email address to send the script to.
Please make sure there is no confidential info in it.
Regards
Guy
ASKER
Guy,
It is porved to be run from Java once I executed the script first from the ISE as I described on the first post.
Once I execute one script on the ISE, the java code executes the scripts with no trouble at all....
It is porved to be run from Java once I executed the script first from the ISE as I described on the first post.
Once I execute one script on the ISE, the java code executes the scripts with no trouble at all....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Tal,
Glad you sorted this out. What you needed was to either use the -noexit flag or close the stream from within java after calling the ps script.
All the best!
Glad you sorted this out. What you needed was to either use the -noexit flag or close the stream from within java after calling the ps script.
All the best!
ASKER
Because it simply works...
You may find that the execution policy is preventing you from running the script from within java.
Try setting your execution policy to unrestricted in your profile and have another go.
Open in new window
Also, have you considered a batch file using logman to start a perfmon?