I'm trying to run a jar file using a bat command with jenkins. and I want to popup the cmd and execute the jar file. but the problem is jenkins execute commands inside its console. Then i inserted "start" command and hoped it'll work coz it creates a separate cmd to run the jar.
here is my bat code
start "window_name" java -jar myjarfile.jar
but when i executing using it jenkins it doesn't create a separate cmd window but it executes the jar file anyhow. it shows this line,
C:\Update>start "window_name" java -jar myjarfile.jar
any idea how to solve this? I want to pop up a black window when executing.
The trick is figuring out in what session you want to start the cmd.exe. On a remote server (which is most often the case with Jenkins), it's not necessary straight forward. Your Remote Desktop Session is not in the same session as someone who is logged in physically at the console.
Bring up Windows Task Manager
Click the Users tab
Note down the ID of the session of the logged in user that you want
Download psexec from Windows Sysinternals
Edited from here downwards
Open elevated command prompt: type cmd into Start's quicksearch, right click cmd.exe, select Run as Administrator.
Type C:\path\to\psexec.exe -accepteula and press enter.
Type C:\path\to\psexec.exe -i 1 cmd and press enter. (If you see a command prompt appear, all is good, close it now)
In Job configuration, configure Execute Windows Batch command step
Write the following:
C:\path\to\psexec.exe -accepteula && C:\path\to\psexec.exe -i 1 cmd /c start C:\full\path\to\java.exe -jar myjarfile.jar
A more detailed explanation is provided in this answer Open Excel on Jenkins CI
Thanks Guys, May be your solutions too will do the trick. Finally what I did is i created a socket program and executed server myself. Then scheduled jenkins to execute the client.(Server in my environment & client in jenkin's environment) When client connects to the server it executes the bat file. Now everything works fine.
Related
I'm new to Java. I already installed Java, JDK and added it to Path, but when I try to run a command (like "java -version") it just flashes a CMD but doesn't show what I want to see. This happens with every command and doesn't even let me run Java code using an IDE. There is no error message, just a CMD flashing every time I try to run something (it also happens when double click the files like "java", "javac", etc).
How do you run these commands? Try running them from an interactive terminal window. Open it by typing windows key + R and then cmd. Then cd into your directory and type your commands there. Alternatively, if your commands are in a .bat file … you may add a pause command at the end.
This is entirely expected as java -version immediately exits after printing the version. This means that if you didn't start it from cmd, PowerShell, or another interactive shell, it opens a window which disappears immediately because the program ended in a fraction of a second.
Start cmd (Command Prompt) or PowerShell (either directly or through Windows Terminal), and run your commands in that interactive shell.
I am writing a bash script that automates installation of TLauncher (Minecraft launcher) and basic dependency management on USBs running Lubuntu 18.04.
Part of the bash script creates a desktop entry under /usr/share/applications for easy launch from the Lubuntu menu.
Here is the entry I am using:
[Desktop Entry]
Encoding=UTF-8
Exec=pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY /usr/bin/java -jar -Dswing.systemlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel ~/.minecraft/tlauncher.jar
Icon=~/.minecraft/icons/default.png
Type=Application
Terminal=false
Name=Minecraft
GenericName=minecraft
StartupNotify=false
Categories=Game
The command pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY /usr/bin/java -jar -Dswing.systemlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel ~/.minecraft/tlauncher.jar works and does launch TLauncher if run in the terminal. However, I feel I am missing something when I put the command in the Desktop Entry.
When I try to open the entry from the Lubuntu menu, the cursor shows that something is loading, but then nothing happens no matter how long I wait. I am also not sure how to debug the Desktop entry. I tried toxdg-open the entry, but I got no output in the terminal and nothing happened either -i.e, TLauncher did not launch.
I tried putting the command in a separate bash file that looks like:
#!/bin/bash
pkexec env DISPLAY=:0 XAUTHORITY=/home/me/.Xauthority /usr/bin/java -jar -Dswing.systemlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel ~/.minecraft/tlauncher.jar
Running that in the terminal bash testscript.sh works and does launch TLauncher.
But when I put it in the desktop entry replacing the exec from the entry above like so:
Exec=/bin/bash /path/to/testscript.sh
It does not work.
The shell scripts have the proper permissions.
I feel like either I'm writing the Desktop Entry's exec value wrong or that pkexec isn't supposed to work from a Desktop Entry the way I am trying to make it work.
I would like to be able to launch TLauncher from a desktop entry via the menu and have a gui popup asking for the password in order to have the command run as root.
Edit:
Using full paths instead of ~ also yields the same result -i.e, it does not work and the above issues remain.
Setting Terminal=true does not solve this for me.
Current solution: Since the command works when run in the terminal, simply have the Desktop Entry run the command with a terminal:
Exec=lxterminal -e "pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY /usr/bin/java -jar -Dswing.systemlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel /home/me/.minecraft/tlauncher.jar"
Notes:
I think I could build off of this to make sure that when the launcher is closed, it is actually closed as I noticed through ps aux that processes aren't actually being killed the way I expect causing strange behavior the next time I open the launcher.
I am running my project as jar using java -jar command in Linux machine. As soon as this program run , It produces logs in another directory. Running my program this way requires me to keep the shell open. Now If I have to see the logs , I can't do that in the same shell. I am forced to do that by either doing the duplicate session or new session. Is there any way I can run the jar as background process and see the logs in the same shell ?
If you don't care about it staying alive, something as simple as nohup java -jar myjar.jar & should work. If you need it to be automatically restarted if it crashes or start automatically at boot, you'll want to look into something like systemd or monit.
im trying to do something simple, i want to start Burp Suite with extra java memory, but i don't want the CMD window to stay open.
If i don't use a .bat file and simple open cmd and type start /b "" java -jar -Xmx2g burpsuite_pro_v1.6.07.jar, Burp opens, the the process is sent to background, but the CMD window stays open. i can, however, close it manually and Burp will keep working.
when i try to put the thing into a CMD window, it will not even be sent to background, Burp stays dependent on the CMD, and i cant even add exit to the file.
i tried to solve the issue by following:
run bat file in background - this worked, but required me to have THREE files, i prefer a more elegant "1 file solution"
Just add the below line in your bat file and the java procees will run in background with no window open!
start javaw {Path of Your jar or Java file}
The following batch file commands should accomplish your purpose:
start "" /B java.exe -Xmx2g -jar burpsuite_pro_v1.6.07.jar
exit
You can probably even leave out the /B switch.
References
How can I run a program from a batch file without leaving the console open after the program start?
How to use the start command in a batch file?
Turns out the solution was simple: using javaw.
the issue was with using java.exe, some attempts even closed the CMD but opened a java.exe window (blank)
modding the file to contain:
start javaw -Xmx2g -jar burpsuite_pro_v1.6.07.jar solved it for me.
In the Process of installing spark 1.0.0 by double clicking the bin/spark-shell windows command script file. Then opened one command prompt file and then immediately closed it self only. Are there any commands required to run this. Could you please tell me step by step process.
First of all, you have to open a terminal. Theorically, you at least have the following on your machine :
cmd (for sure)
powershell (maybe not, if you're using Vista or less).
From there, you have two options :
if you added path_to_spark_folder\bin to your PATH variable (see there for more informations), you can run spark-shell as soon as the console is opened
if you didn't, you'll have to go to path_to_spark_folder\bin yourself, using the cd command.
You now can run spark-shell.