Windows OS commands are not executing in Spring Shell - java

I am using spring shell to develop command line interface application, I am facing one issue in windows machine, On Linux machine i am able to execute OS commands by using !<OS Command>,
but this is not working in windows machine. Spring shell says
Unable to execute command, The system can not find the specified command.
Please let me know how can i execute windows command in Spring shell running in windows platform( commands like date, time,path etc)
Thanks in advance.

date, time, path, etc. are built-in commands of the windows command shell. It seems that these built-in commands are not available within spring-shell and spring-shell looks after commands which exist real as file in the windows path.
Windows-Commands like calc (! calc) which are not built-in are available.

Related

Will below command work as it as on jenkins for running my jar file with command line arguments?

I have built an executable jar file which is also a standalone SpringBoot Application. The requirement is that I have to run this jar file from command line which also provides command line arguments which are meant to override application.properties properties and will be used further.
I have tried and this works perfectly when ran from Windows Command Prompt.
Now I further want to deploy this on jenkins and run the same jar file usign jenkins using the command:Note that the command is important since it overrides application.properties.
Will it work in jenkins? Should i go with "Execute Shell" or "Execute Windows batch command" for it in jenkins? I would be trying it but need o know .
Command: java -jar myJArName.jar --server.port=10 --another.argument=1 --another.argument=2
Yes, you can use execute shell as you mentioned above if:
Java is installed on the host that Jenkins runs on
java is part of $PATH (you can check this by running which java on your jenkins host)
myJarName.jar is actually on the host jenkins runs on
Btw. I assume Jenkins runs on a Linux host. Otherwise you might have to use Execute Windows batch command which will work in a similar way to execute shell, but I never used it.

DTEXEC doesn't trigger dtsx package in a power shell when triggered from java but works from command prompt on local machine

I'm calling a dtsx file in PowerShell(test.ps1) using below:
& $dtexec /f "$dtsx"
This works fine when I run the test.ps1 from command prompt in local machine but the same doesn't even trigger when test.ps1 is triggered from a java application.
please help.
I'd check if any other Powershell runs for You when started from Java, and only this particular one fails.
At some point I had similar problem. It turned out, that I was using Powershell module that required to 64bit powershell instance while I was running 32bit java process. This in turn was spawning 32bit Powershell process (You can check that with [Environment]::Is64BitProcess) that could not run what I was asking it to run.

running application from cmd as administrator through java code

I executed the netsh command from the CMD that was manually opened by me by right clicking the CMD icon from the start and then selecting run as administrator from the options.It worked fine.Now I tried to run the netsh command through my java code,then it is not working.Nothing is happening when i run that code.I want to ask that I can run applications like notepad.exe from the cmd by calling appropriate methods of the runtime class from my java code,But how can I open the same application with the administrator priviliges from my java code.r.exec("notepad"); where r is an object reference to the runtime class will run the application,but the notepad so opened will not be in administrator mode.Actually I guess that learning to run the application in administrator mode from CMD will be enough to do the work done as The corresponding CMD command will be passed as the argument to the exec() method of the Runtime class.So my questions are:
How to run any application from CMD in windows 8 with administrator privilliges?
The way i want to implement the use of netsh is a good thing to practise or there is some other way out i must use these commands from my java code.
I have seen some commands while googling but they where not working out for me,like runas /user:administrator "notepad.exe" etc.
Thanks
You cannot use the runas /user:administrator approach, as that requires a password input which you cannot provide from an external source (such as a Java application) for security reasons.
I had a similar issue to you in the past, and I solved it using PsExec, running the process on localhost with an administrator username and password allowed me to execute external applications as an administrator.
Using your example you could run:
PsExec.exe \\\\127.0.0.1 /accepteula -u USER -p PASSWORD notepad.exe
The "/accepteula" flag prevents the requirement to accept the EULA interactively when run on a machine for the first time.
This approach may require a bit of tweaking to get working with your setup, but hope it gives you a starting point.

How do you run a Java UI application as a Group Custom User Inteface for windows (Possibly using Group Policies)?

I've tried setting the Custom User Interface GPO option to
java -jar GyroUI.jar
as well as using the full path
C:\Program Files\jre7\bin\java.exe -jar GyroUI.jar
But neither seem to result in anything except the desktop background.
I know this works normally as I can run the jar file just fine using the command prompt, and I get the UI as expected.
C:\Program Files\jre7\bin\java.exe -jar "C:\Program Files\Sahara\GyroUI.jar"
Ended up being the solution, the problem was being caused by the application crashing, not by the shell failing to launch.

Run .sh (from linux) scripts on windows using eclipse

I have a .sh scripts in Linux.
I want to create a form in Java (eclipse) on Windows
and execute those .sh files.
Is there any simple way to do this?
At first you need to be able to run those shell scripts on target computer.
So try Cygwin, MinGW or other Unix emulators.
If run successfully next step is to use Runtime.getRuntime().exec(command) for running script. You have to set up environment (run another command before) to make it working.
The gcc compiler on CDT Eclipse for Windows is working this way.
.sh is a a shell script, most likely the default shell for a linux system, i.e. bash, so no, it won't run on your Windows machine. You can try Cygwin shell but still there is no guarantee that it will run. You will have to rewrite it for Windows batch script or your some other scripting language.
As far as Java is concerned, you can write in Linux and the code is portable to any other machine supporting JavaVM.
No there isn't. Perhaps intalling Cygwin would be an option, but I would not recommend to go that way.
Or perhaps I misunderstood. If you like running those scripts on your linux-machine, you can trigger a remote execution easily by using the appropriate java commmands or libraries (eg: jssh or anything like that).

Categories