This seems like such a basic thing..kill app & restart it..
I have this batch file configure to run daily through windows task scheduler:
#ECHO OFF
::Daily reboot to limit ram usage
taskkill /F /IM javaw.exe
::
:: start app again
::
start app.jar
The script is run each day successfully according to windows but it is only closing the program not starting it again. When I double click my .bat file it works just fine..
What am I missing?
Well I'm in my first year of bachelor only using BlueJ so far to learn java so I apologize.
Happy that I now know the task run from c:\win\sys32. I could see the logs from the java app there not finding the libraries. so the #CD /D "%~dp0" I'll try to remember for sure. Thx
final code:
#CD /D "%~dp0"
::Daily reboot to limit ram usage
taskkill /F /IM javaw.exe
::
:: start app again
::
start java -jar d:\path\to\app.jar
full path to javaw.exe was not needed, only diff when running the app with task scheduler is that the last line in log should be "added to SystemTray" making the app visible. Now it is running hidden, which is ok for it's use but I'll try to figure out on my own why.
(just "start app.jar" is also working just fine btw with the #CD /D "%~dp0" on top.)
thx,
First make sure you have configured environment variable for running java.exe . If not, refer this .
Secondly, always use complete path to start/kill your jar execution.
The command to run your application is:
java -jar app.jar
Related
I am currently creating an improvised installer for a cople software packages. To do this I have to install a couple MSI packages first before doing a couple file operations.
To install an MSI package I am using the following command:
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
This command works and installs the package instantly and witout any problems via CMD.
But when I put this command in my batch file and execute it as an administrator, I get the following error:
This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package
What cold be the problem? Using the same command via the console works flawlessly, only the batch file throws the error...
EDIT: I have also tried the /a parameter in order to install it as an administrator and it does not work either. Full command in batch file:
start /wait msiexec /qn /a "Myinstaller V2.1.msi"
EDIT2: I just realized that it only does not work when I start the batch file with Right click > Run as administrator
When I open a console with administrative rights and start my batch file it works for some reason...
Is there a way to make it work with the Right click > Run as administrator method?
SOLUTION: Thanks to RGuggisberg's answer I now know that the directory changes once the file is executed as an administrator. With a small change the installer gets fired up as an admin and works perfectly starting the installer from a relative path in the same directory:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
pause
I've now also implemented a feature to detect wether or not the installation fails or not:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
if %ERRORLEVEL% EQU 0 echo SUCCESSFULL
if NOT %ERRORLEVEL% EQU 0 echo MyProgram installation FAILED
pause
The current directory changes when you run as administrator. If you want to prove that to yourself, see this post
Difference between "%~dp0" and ".\"?
Include the full path to your filename and it will work.
I am running this batch process on Windows cmd in order to update some files on a project - since the framework doesn't allow to update a plugin I am uninstalling, cleaning up and reinstalling, but that's not related to the question.
My problem is that something on the first command, inside the ionic.cmd process, stops the entire process, even when successful. I suppose it features some kind of exit statement which halts the entire process and returns me to the cmd prompt without running next files.
I have tried to change that command by some bus-process embedding like START cmd /K ... and so, with no success. So, how can I batch run that command without the whole script stopping at that line?
#echo off
pushd %~dp0\..
ionic cordova plugin remove com.mirasense.scanditsdk.plugin
del "platforms\android\app\src\main\res\drawable\*.xml"
del "platforms\android\app\src\main\res\layout\*.xml"
del "platforms\android\app\src\main\res\values\colors.xml"
ionic cordova plugin add lib\scandit
popd
As requested, here's my comment as an answer.
You've identified that ionic is actually ionic.cmd; you therefore need to use the Call command, which allows return to the initiating script upon completion.
#Echo Off
Pushd "%~dp0..\"
Call ionic.cmd cordova plugin remove com.mirasense.scanditsdk.plugin
Del /Q "platforms\android\app\src\main\res\drawable\*.xml"
Del /Q "platforms\android\app\src\main\res\layout\*.xml"
Del "platforms\android\app\src\main\res\values\colors.xml"
Call ionic.cmd cordova plugin add lib\scandit
PopD
I made a .bat file which is supposed to run Thunderbird minimized.
Here's what I put in it so far:
start /min "" C:\"Program Files (x86)"\"Mozilla Thunderbird"\thunderbird.exe runas /user:Administrator
I tried several tests:
- Removing /min
- Adding the runas option for administrator rights
- Adding the first empty quotes after start
- Writing the whole path into quotes
- ...etc.
Everything that happens is the .bat launches, but nothing furthermore happens.
I have no error in the CMD window.
Why isn't it working ??
My purpose is to put that .bat in startup folder so that Thunderbird launches minimized on startup.
I used to use an extension (MinimizeOnStartup) for Thunderbird, but it's no longer compatible with latest version and I couldn't manage to find any alternative.
I read through here, it wasn't enough to help:
A batch file to minimize other applications
Can you help me?
Thank you.
Using Windows 10.
Try the following (modify it accordingly)
cd C:\Program Files (x86)\Mozilla Thunderbird\
start /min thunderbird.exe runas /user:Administrator
A solution posted on reddit https://www.reddit.com/r/Thunderbird/comments/bnt6u3/ive_created_a_small_script_to_minimize/ ...
This is Windows only. You'll need NirCMD for this. NirCMD will trigger the "Minimize" Event after we've started Thunderbird. Get it here: https://www.nirsoft.net/utils/nircmd.html
The script:
START "" "C:\Program Files\Mozilla Thunderbird\thunderbird.exe"
timeout /T 3 /nobreak
"nircmd.exe" win min process "thunderbird.exe"
We have a configured TFS CI which is making our build. After a build I`d like to have my simple executable application to be deployed to specific folder on the server and then started.
I decided to do this with post-build step and batch script. Everything works perfectly except one:
when the application is stared, build agent(the one who runs my script) hangs.
Here is how I start my application from the script:
start /b %depldir%\MyApp.exe [params] > log.txt
So I start it in backgroound and redirect std out/error to file.
Application is started correctly but build process won`t finish untill I kill the application.
How do I start my application without build agent waiting for it to finish?
I'm not sure if this is a bug but if you use start /b something > logfile.txt the new and hidden cmd window is started with parameter /k. This forces the hidden window to stay active. This makes the calling bat wait for it to exit and this is why your build won't terminate. To verify this I've created two files:
starter.bat:
start /b tostart.bat > log.txt
tostart.bat:
echo started
When I start starter.bat the cmd doesn't terminate and in the task manager the following process appears:
cmd.exe USER 00 00:00:00 1.400k C:\Windows\system32\cmd.exe /K
tostart.bat
/K means:
/K Run Command and then return to the CMD prompt.
This is useful for testing, to examine variables (taken from http://ss64.com/nt/cmd.html)
To cut a long story short: it works fine when you replace start /b with call. Unfortunately call doesn't have a parameter like /b so your application won't start in background. I don't know whether this is a problem for you.
If it is: I've faced similar problems with my Jenkins build server. My solution was to create a task which runs my application (in background). Instead of calling the program itself I just call SCHTASKS /Run /TN "TASK_NAME". This command just triggers the task without waiting. This way you can also avoid problems with permissions etc.
I have created a python script that I would like to run every time I start my computer.
So I started creating a batch file that could later be put into my startup folder.
I tried this:
#echo off
start "C:\Users..........." (I gave the exact path)
and when I run it you can see the python script pop up for a moment, but then shuts down. What am I doing wrong?
this works here:
#echo off
start /b "" "%ProgramFiles%\Python33\python.exe" "%UserProfile%\Test.py" "more parameters"
pause