I want to compress multiple input file into multiple output minified files like this :
Input :
file1.css
file2.css
file3.css
Output:
file1-min.css
file2-min.css
file3-min.css
I'm trying to achieve that with the following command line :
java -jar yuicompressor-2.4.8.jar *.css -o $.min.css
It is not helping me at all > it creates a $.min.cs and not file1-min.css etc...
You guys have an idea how to achieve that ?
I have search some answer for this into stackoverflow, without success.
Thanks for your help,
Regards.
Update
Here is the solution :
#echo off
setlocal
echo doing some css min
for %%F in (%cd% *.css) do (
echo %%~nF
java -jar yuicompressor-2.4.8.jar %%F -o min\%%~nF.min.css
echo "done"
)
)
I think you'll need to loop over your css files and call yuicompressor for each item.
For example, in windows batch
FOR /F %G IN ('dir /b C:\yourcssPath\*.css') DO java -jar yuicompressor-2.4.8.jar %G -o %G.min.css
Related
So, it might be a noob question but am still stuck with it. I have a batch command in a batch file as:
#echo off
start "" /D "C:\UpworkUP" upwork.exe --args -url=chrome://crash -disable-web-security -script-url=https://172.27.68.6/pre_alpha/
My doubt is how do I run this command from java itself without calling the batch file here. So per say, I do not want the batch file, I just need to run the command in it from java directly.
Making a batch file showing how arguments are being parsed.
#Echo %1
#Echo %2
#Echo %3
#Echo %4
#Echo %5
#Echo %6
#Echo %7
#Echo %8
#Echo %9
shows this result, how your arguments are being parsed most likely.
C:\Users\User>"C:\Users\User\Desktop\New Text Document.bat" --args -url=chrome://crash -disable-web-security -script-url=https://172.27.68.6/pre_alpha/
--args
-url
chrome://crash
-disable-web-security
-script-url
https://172.27.68.6/pre_alpha/
Which shows a errant space after crash. And maybe you neeed to escape = with a ^, so ^=. Fix first error, then see if you need to escape the equals.
Use:
Runtime.getRuntime().exec("YOUR_COMMAND");
About Runtime
For the close everything crowd: This is not a duplicate of the question How to check if a process is running via a batch script because there may be multiple java.exe processes running (as they are in my case) and I need only to check for the specific jar. That's why I have written jar java application in the title.
I have a "Minecraft server" icon on my desktop that starts Spigot minecraft server. I use such run.bat file to do the job:
:start
java -Xmx1024M -Xms1024M -jar spigot-1.8.7.jar
pause
goto start
It's infinite loop to make server restarting simpler. Now it sometimes happens that I, or somebody else who's using the computer, try to start the server while it's already running. I would like to prevent this from happening. Something along:
IF spigot_server_running (
echo The server is already running. If you can't connect, try to check the console window for errors.
echo if all else fails, terminate the java process from task manager.
pause
exit 1
)
What can I do to detect it? I guess list of running processes can be parsed similarly to what Linux's grep does. But isn't there some command line tool for this distributed along with java JRE or JDK? I wouldn't install extra program for this task but I would prefer official Java API. But remember it must work with batch or Windows CScript files.
So I found out that there's this jps utility which conveniently lists running java processes and their arguments. I meantioned in the comments I think there's such a thing, but it took a while to dig out the proper use. I created following script:
#echo off
setlocal enabledelayedexpansion
echo Checking for %1
for /f "tokens=1" %%i in ('jps -m ^| find "%1"') do (
echo Jar already running
goto end
)
echo Jar not running
:end
pause
Usage:
> isjarrunning.bat something.jar
The name is case-sensitive!
In order to use this script in IF statements, it must be tweaked:
isjarrunning.bat
#echo off
IF [%1] == [] (
echo Invalid parameter. Usage:
echo isjarrunning.bat NameOfTheJarFile.jar
exit /B 2
)
for /f "tokens=1" %%i in ('jps -m ^| find "%1"') do (
exit /B 1
)
exit /B 0
Usage in your scripts:
testjarrunning.bat
#echo off
call isjarrunning.bat MyProgram.jar
echo Error level: %errorlevel%
if errorlevel 1 (
echo Jar file already running!
exit /b 1
) ELSE (
echo Starting jar file
start javaw -jar path\MyProgram.jar
)
echo Ende
I have a jar file which is a program which accept user input and processes it. I am running this jar file using the below shell script:
PR=`basename $0`
cdt=`date +'%H:%M:%S %d/%m/%Y'`
cd $HOME/myprogram
java -cp $HOME/myprogram/ifxjdbc.jar:$HOME/myprogram/jarprogram.jar:. MyProgram $#
cdt=`date +'%H:%M:%S %d/%m/%Y'`
The problem I am facing with this is, I want to restrict the user from exiting the application using any of the combinations of the below commands.
For example:
Ctrl + z
Ctrl + c
Ctrl + break
Please help me.
I recommend to you use simple start and stop script for your program;
1) create sh script with name start_myprogram.sh and put into the file ;
PR=`basename $0`
cdt=`date +'%H:%M:%S %d/%m/%Y'`
cd $HOME/myprogram
nohup java -DMY_PROG -cp $HOME/myprogram/ifxjdbc.jar:$HOME/myprogram/jarprogram.jar:. MyProgram $#
cdt=`date +'%H:%M:%S %d/%m/%Y'`
2) create sh script with name stop_myprogram.sh and put into the file ;
#!/usr/bin/sh
USER=`whoami`
PID=`ps -xfu $USER| grep java | grep MY_PROG | grep -v grep | awk '{ print $2 }'`
if [ -n "$PID" ]
then
kill $PID
else
echo MY_PROG is not running.
fi
3) start your program ./start_myprogram.sh &
4) anytime whenever you want stop your program ./stop_myprogram.sh
*This is maybe not answer of your question but at least you dont need to implement anything more.
I would suggest the following change in the script to get to the desired requirement.
It seems that you need some kind of function which will catch these commands and not let the commands get executed. Shell script can have this kind of functionality by implementing the use of trap.
You can make change in your script like this:
PR=`basename $0`
cdt=`date +'%H:%M:%S %d/%m/%Y'`
cd $HOME/myprogram
#Add these two lines in the code for catching exit commands
trap '' 20
trap ' ' INT
java -cp $HOME/myprogram/ifxjdbc.jar:$HOME/myprogram/jarprogram.jar:. MyProgram $#
cdt=`date +'%H:%M:%S %d/%m/%Y'`
Its very simple to use traps in shell scripts. Hope this works for you.
So, here's the problem I encountered. I wrote a simple .bat file to run weka on some data sets I had but Java recently updated itself and it stopped working. My old code was this:
#ECHO OFF
SET CLASSPATH = "C:\Program Files (x86)\Weka-3-6\weka.jar"
FOR /r %%I IN (*.arff) DO (
ECHO Running %%~nI.arff
java weka.classifiers.meta.FilteredClassifier -t %%~nI.arff -F "weka.filters.unsupervised.attribute.Remove -R 1,3,4,5" -W weka.classifiers.functions.LinearRegression -x 10 >> results.txt
ECHO >> results.txt
)
This worked before and it did the job I asked of it. However, after the java update, I kept getting the error "Could not find or load main class weka.classifiers.meta.FilteredClassifier". I couldn't figure it out because the directory names and class names were exactly correct. So, I changed the code to this:
#ECHO OFF
SET CLASSPATH = "C:\Program Files (x86)\Weka-3-6\weka.jar"
FOR /r %%I IN (*.arff) DO (
ECHO Running %%~nI.arff
java -cp "C:\Program Files (x86)\Weka-3-6\weka.jar" weka.classifiers.meta.FilteredClassifier -t %%~nI.arff -F "weka.filters.unsupervised.attribute.Remove -R 1,3,4,5" -W weka.classifiers.functions.LinearRegression -x 10 >> results.txt
ECHO >> results.txt
)
And it worked again. Can anyone tell me why this happened? The only thing I can think of is that the Java update isn't playing nice with itself somehow. Any insight would be appreciated thanks.
SET WEKA_HOME=c:\Program Files (x86)\Weka-3-6
SET CLASSPATH=%CLASPATH%;%WEKA_HOME%\weka.jar
bash learn.sh
I'm trying to set up a Minecraft Server and actually everything works fine. I'm starting the Server with a launch.bat file.
"%ProgramFiles%\Java\jre1.8.0_20\bin\java.exe" -Xmx2G -Xms1G -jar Tekkit.jar nogui
pause
And I have a second .bat file for backup purposes.
SET COUNTER=0
:loop
SET /a COUNTER=%COUNTER%+1
XCOPY "Server\*" "c:\Users\Benjamin\Desktop\Tekkit Server\backups\server_backup_%COUNTER%" /i /s
PING 1.1.1.1 -n 1 -w 600000 > NUL
goto loop
Now, all I'm trying to do is to start the two .bat files simultaneously, using only one .bat file.
I tried it with a third .bat file to start all:
start cmd /k CALL "C:\Users\Benjamin\Desktop\Tekkit Server\Server\launch.bat"
start cmd /k CALL "C:\Users\Benjamin\Desktop\Tekkit Server\backup.bat"
pause
It will actually start both .bat files, but suddenly, they start acting up and won't find their own files again:
C:\Users\Benjamin\Desktop>"C:\Program Files\Java\jre1.8.0_20\bin\java.exe" -Xmx2G -Xms1G -jar Tekkit.jar nogui
Error: Unable to access jarfile Tekkit.jar
C:\Users\Benjamin\Desktop>pause
Drücken Sie eine beliebige Taste . . .
C:\Users\Benjamin\Desktop>SET COUNTER=0
C:\Users\Benjamin\Desktop>SET /a COUNTER=0+1
C:\Users\Benjamin\Desktop>XCOPY "Server\*" "c:\Users\Benjamin\Desktop\Tekkit
Server\backups\server_backup_1" /i /s
File * not found
0 File(s) copied
C:\Users\Benjamin\Desktop>PING 1.1.1.1 -n 1 -w 600000 1>NUL
All three .bat files are in different directories.
Does anybody have a clue what I could do about my problem (besides stop being lazy, trying to reduce 2 clicks down to one ;) )
Thanks a lot
Benny
The problem is most likely your path directory. when you do cmd, cd to the "right" directory first, then run the bat file. for example:
cmd /k "cd /my/app/path && app.bat"
the && is the separator for multiple commands